---
title: "How Voters Respond to Economic Shocks from Abroad - Costin Ciobanu and Joost
  van Spanje - Replication file (Political Science Research and Methods, 2025)"
output:
  html_document: default
date: "2025-08-19"
editor_options:
  chunk_output_type: console
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# R version

The analysis was conducted using R version 4.3.2 (2023-10-31).

# Data and code credits

We use data from the European Social Survey (wave 4) for our main analyses. For supplementary analyses, we draw on the ParlSpeech dataset (Rauh and Schwalbach 2020), the EUSpeech dataset (Schumacher et al. 2020), the American National Election Studies (2008), the KOF Globalization Index dataset (Gygli et al. 2019), Eurobarometer data (Flash Eurobarometer 251, Standard Eurobarometer 69, and Standard Eurobarometer 70), Dow Jones Factiva, and Google Trends. We are grateful to all those involved in the collection of these datasets. For the balance tests, we use R code from Hartman and Hidalgo (2018) and appreciate the opportunity to build on their work.

# Load packages and relevant functions/themes

```{r}

# Load relevant packages
pacman::p_load(foreign, psych, texreg, tidyverse, dplyr, plyr, data.table, readxl, grid, gridExtra, zoo, MASS, miceadds, gdata, tidyquant, scales, patchwork, ebal, lfe, haven, lubridate, readtext, cobalt, estimatr, xtable, ggthemes, ggpubr, fastDummies, kableExtra, randomizr, gghighlight, ggrepel, mosaic, sciplot, stringi, knitr, margins, sjPlot, stats, stargazer, effects, diagis, syuzhet, quanteda)

# Different functions
`%nin%` <- function (x, table) is.na(match(x, table, nomatch=NA_integer_))
select = dplyr::select

# Plot themes (ggplot)
theme = theme_bw() +
  theme(plot.title = element_text(colour = "blue", hjust = 0.5),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 20, face="bold"),
        strip.text.y = element_text(size = 20, face="bold"),
        axis.text.x = element_text(size=20),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 20))

theme2 = theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold")) +
  theme(plot.subtitle = element_text(hjust = 0.5)) +
  theme(text = element_text(size=20)) +
  theme(strip.text.x = element_text(size = 20, face="bold")) +
  theme(strip.text.y = element_text(size = 20, face="bold")) +
  theme(axis.text.x= element_text(size = 20)) +
  theme(axis.text.y = element_text(size = 20)) +
  theme(axis.title.x= element_text(size = 26)) +
  theme(axis.title.y = element_text(size = 26)) 

```

# Load main dataset - ESS Wave 4

```{r}

# The main dataset used for the analysis is the European Social Survey wave 4, that can be freely downloaded from here: https://ess.sikt.no/en/series/321b06ad-1b98-4b7d-93ad-ca8a24e8788a. For the analysis, we employ version 4.5.

ess = read_dta("Data/ESS4e04_5.dta") %>%
  filter(cntry %in% c("CH", "DE", "ES", "GB", "NL", "NO"))

# Note: We select only the countries with observations collected both before and after the Lehman Brothers bankruptcy announcement (15 September 2008). We also exclude DK and IL due to having too few observations for the analysis.

```

# Recode the data

```{r}

ess = mutate(ess,
             
             # Date of the interview
             inwyys = ifelse(is.na(inwyys), "2008", inwyys),
             Date = dmy(trim(paste(inwdds, "-", inwmms, "-" ,inwyys))),
             
             # Period - pre (0) vs. post (1)-Lehman Brothers announcement
             Post = ifelse(Date <= "2008-09-15", 0, 1),
             
             # Placebo date
             Placebo = ifelse(Date <= "2008-09-01", 0, 1),
             
             # Linear trend
             Linear_trend = ifelse(Date > "2008-09-15", interval(Date, ymd("2008-09-15")) %/% days(-1), 0),

             # Satisfaction with the national economy
             Econ_sat = stfeco,
             
             # Satisfaction with the national government
             Gov_sat = stfgov,
             
             # Controls
             Sex = gndr,
             Age = agea,
             Education_highest = ifelse(cntry == "GB", edlvgb, eisced),
             Residence = domicil,
             Marital_status = maritala,
             Income_subjective = hincfel,
             Ethnic_minority = blgetmg,
             Country_citizen = ctzcntr,
             Paidwork_7days = pdwrk,
             Unempl_7days = uempla,
             Educ_7days = edctn,
             Retired_7days = rtrd,
             Disabled_sick_7days = dsbld,
             Housework_7days = hswrk,
             
             # Likelihood of becoming unemployed
             Likely_unempl = case_when(
               lkuemp %in% c(3:4) ~ 1,
               lkuemp %in% c(1:2, 55) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Likelihood of not having enough money for households’ necessities
             Likely_notenough_money = case_when(
               lknemny %in% c(3:4) ~ 1,
               lknemny %in% c(1:2) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Political interest
             Political_interest_b = case_when(
               polintr %in% c(1:2) ~ 1,
               polintr %in% c(3:4) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Politics is complicated
             Politics_complicated = polcmpl,

             # Other variables (e.g., for balance checks, additional analyses)
             Religiosity = rlgdgr,
             Member_discrgroup = dscrgrp,
             Born_country = brncntr,
             Type_org = tporgwk,
             Income_source = hincsrca,
             Total_income = hinctnta,
             Mobile_phone = mbltph,
             
             # Turnout - most recent legislative election
             Turnout_yes = ifelse(vote == 1, 1, 0),
             
             # Being closer to a party
             Partisanship_yes = ifelse(clsprty == 1, 1, 0),
             
             # Trust in key political institutions
             Trust_Parliament = trstprl,
             Trust_politicians = trstplt,
             Trust_parties = trstprt,
             
             # Satisfaction with education
             Edu_sat = stfedu,
             
             # Satisfaction with health services
             Health_sat = stfhlth, 
             
             # Satisfaction with democracy
             Dem_sat = stfdem,
             
             # Closer to the Prime Minister party
             IncumbentPM_partisan_ch = case_when(
               prtclbch %in% c(1, 5) ~ 1,
               prtclbch %in% c(2:4, 6:14) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_partisan_de = case_when(
               prtclbde %in% 2 ~ 1,
               prtclbde %in% c(1, 3:8) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_partisan_nl = case_when(
               prtclbnl %in% 1 ~ 1,
               prtclbnl %in% c(2:13) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_partisan_no = case_when(
               prtclno %in% 3 ~ 1,
               prtclno %in% c(1:2, 4:10) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_partisan_es = case_when(
               prtclbes %in% 2 ~ 1,
               prtclbes %in% c(1, 3:74) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_partisan_gb = case_when(
               prtclgb %in% 2 ~ 1,
               prtclgb %in% c(1, 3:15) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_partisan = coalesce(IncumbentPM_partisan_ch, IncumbentPM_partisan_de, IncumbentPM_partisan_nl, IncumbentPM_partisan_no, IncumbentPM_partisan_es, IncumbentPM_partisan_gb),
             
             # Incumbent Prime Minister party vote in the most recent legislative election
             IncumbentPM_vote_ch = case_when(
               prtvtbch %in% c(1, 5) ~ 1,
               prtvtbch %in% c(2:4, 6:16) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_vote_de = case_when(
               prtvbde1 %in% 2 ~ 1,
               prtvbde1 %in% c(1, 3:8) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_vote_nl = case_when(
               prtvtcnl %in% 1 ~ 1,
               prtvtcnl %in% c(2:14) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_vote_no = case_when(
               prtvtno %in% 3 ~ 1,
               prtvtno %in% c(1:2, 4:10) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_vote_es = case_when(
               prtvtbes %in% 2 ~ 1,
               prtvtbes %in% c(1, 3:10, 74:76) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_vote_gb = case_when(
               prtvtgb %in% 2 ~ 1,
               prtvtgb %in% c(1, 3:15) ~ 0,
               TRUE ~ as.double(NA)),
             
             IncumbentPM_vote = coalesce(IncumbentPM_vote_ch, IncumbentPM_vote_de, IncumbentPM_vote_nl, IncumbentPM_vote_no, IncumbentPM_vote_es, IncumbentPM_vote_gb),
             
             # Survey weights
             Weights = pspwght)

```

# Main paper

## Table 1

```{r results='asis'}

tab1 = list()

tab1[[1]] = lm(data = ess, weights = Weights, Econ_sat ~ Post + factor(cntry))

tab1[[2]] = lm(data = ess, weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tab1[[3]] = lm(data = ess, weights = Weights, Gov_sat ~ Post + factor(cntry))

tab1[[4]] = lm(data = ess, weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 90%;">') # use htmlreg for knitting
screenreg(tab1, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "Full sample", "Full sample"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variables for the models: satisfaction with the national economy (0-10) - models 1-2; satisfaction with the national government (0-10) - models 3-4. All models use survey weights.", caption = "Satisfaction with the national economy and national government (all countries)")
#cat('</div>')

```

## Figure 1

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.7,0.4,0.1), limits = c(-0.7,0.4), labels = label_number(accuracy = 0.1)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national economy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/Fig1_ESS_Econsat_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

## Figure 2

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national government\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/Fig2_ESS_Govsat_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

# Online Appendix

## Appendix A

### Table A.1

```{r warning=FALSE}

descriptives <- c("Gov_sat", "Econ_sat", "Likely_unempl", "Likely_notenough_money", "Political_interest_b", "Politics_complicated", "Post", "Sex", "Age", "Education_highest", "Residence", "Marital_status", "Income_subjective", "Ethnic_minority", "Country_citizen", "Paidwork_7days", "Unempl_7days", "Educ_7days", "Retired_7days", "Disabled_sick_7days", "Housework_7days", "Turnout_yes", "IncumbentPM_vote")

data_sub <- dplyr::select(ess, descriptives)

psych::describe(data_sub, skew = TRUE, check = TRUE) %>%
  as.data.frame() %>%
  dplyr::select(n, mean, sd, median, min, max, se) %>%
  as.data.frame() %>%
  round(2) # %>% xtable()

```

## Appendix B

### Read the Google Trends data

```{r}

# Google Trends - "Lehman Brothers" search term
trends_lehman  = as_tibble(read_excel("Data/Trends_Lehman.xlsx", na = ".", col_names = TRUE)) %>% mutate(Week = ymd(Week))

# Google Trends - "crisis" search term (country-specific; see figure note for exact terms used per country)
trends_crisis  = as_tibble(read_excel("Data/Trends_crisis.xlsx", na = ".", col_names = TRUE)) %>% mutate(Week = ymd(Week))

```

### Figure B.1

```{r warning=FALSE, fig.width=20, fig.height=12.5}

trends_lehman %>%
  mutate(Week = ymd(Week),
         Count = ifelse(Count == "<1", "0", Count),
         Count = as.numeric(Count)) %>%
  filter(Country %nin% c("Denmark", "Israel")) %>%
  ggplot(aes(x = Week, y = Count, colour = Country)) +
  geom_point(size = 4) + 
  geom_line(size = 1) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-01"), y = 70, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_y_continuous(breaks = seq(0,100,20)) + 
  scale_x_date(breaks = seq(from = min(trends_lehman$Week), to = max(trends_lehman$Week), by = 14), date_labels = "%d-%m") +
  facet_wrap(~Country, ncol = 3) +
labs(y = "Google Search Trends - Lehman Brothers", x = "Week Starting Day (January - December 2008)") + 
  theme_bw() +
  theme(plot.title = element_text(colour = "blue", hjust = 0.5),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigB1_GoogleTrends2008.pdf", dpi = 1200, width = 20, height = 12.5, unit = "in")

```

### Figure B.2

```{r warning=FALSE, fig.width=20, fig.height=12.5}

trends_crisis %>%
  mutate(Week = ymd(Week),
         Count = ifelse(Count == "<1", "0", Count),
         Count = as.numeric(Count)) %>%
  filter(Country %nin% c("Denmark")) %>%
  ggplot(aes(x = Week, y = Count, colour = Country)) +
  geom_point(size = 4) + 
  geom_line(size = 1) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-01"), y = 80, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_y_continuous(breaks = seq(0,100,20)) + 
  scale_x_date(breaks = seq(from = min(trends_crisis$Week), to = max(trends_crisis$Week), by = 14), date_labels = "%d-%m") +
  facet_wrap(~Country, ncol = 3) +
labs(y = "Google Search Trends - Crisis", x = "Week Starting Day (January - December 2008)") + 
  theme_bw() +
  theme(plot.title = element_text(colour = "blue", hjust = 0.5),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigB2_GoogleTrends2008_crisis_v2.pdf", dpi = 1200, width = 20, height = 12.5, unit = "in")

```

### Hartman and Hidalgo (2018) functions

```{r warning=FALSE, message=FALSE}

# Packages
library(Hmisc)
library(sna)
library(gridExtra)
library(grDevices)
library(sandwich)
library(reshape2)
library(parallel)
library(xtable)

# Functions
equiv.t.test <- function(x, y, alpha = .05, epsilon = .2, std.err = "nominal", cluster.x = NULL, cluster.y = NULL) {
  x = x[!is.na(x)]
  y = y[!is.na(y)]
  
  
  dbar <- mean(x) - mean(y)
  m <- as.double(length(x))
  n <- as.double(length(y))
  N <- m+n
  x.var <-  var(x)
  y.var <- var(y)
  non.cent <- (m*n*epsilon^2)/N
  critical.const <- sqrt(qf(alpha,1,N-2,non.cent))
  
  se = sqrt((m-1)*x.var + (n-1)*y.var) / sqrt(m*n * (N-2)/N)
  df = N - 2
  
  t.stat <-  dbar / se
  p = pf(abs(t.stat)^2, 1, df , non.cent)
  obs_smd = (mean(x) - mean(y)) / sd(y)
  inverted <- try(uniroot(function(x) pf(abs(t.stat)^2, 1, N-2, ncp = (m*n*x^2)/N) - ifelse(pf(abs(t.stat)^2, 1, N-2, ncp = (m*n*0^2)/N) < alpha, pf(abs(t.stat)^2, 1, N-2, ncp = (m*n*obs_smd^2)/N), alpha), c(0,10*abs(t.stat)), tol = 0.0001)$root, silent = TRUE)
  if(class(inverted) == "try-error") {
    inverted = NA
  }
  rej = abs(t.stat) <= critical.const
  return(list(t.stat = t.stat, critical.const = critical.const, power = 2*pt(critical.const, N-2)-1, rej = rej, p = p, inverted = inverted))
}


run_equiv = function(X, Tr, epsilon.method = "std.effect", Y = NULL, 
                     custom.epsilon = NULL, std.err = "nominal", type = "equiv.t.test", 
                     fdr_correct = FALSE, cluster.x = NULL, cluster.y = NULL) {
  switch(epsilon.method,
         std.effect = {
           tol = abs(mean(Y[Tr == 1], na.rm = TRUE) - mean(Y[Tr == 0], na.rm = TRUE)) / sd(Y[Tr == 0], na.rm = TRUE)
         }, 
         custom = {
           if(is.null(custom.epsilon)) stop("ERROR: Must enter a custom epsilon value to use the 'custom' epsilon.method.")
           tol = custom.epsilon
         },
         strict = {
           tol = 0.36
         }, 
         liberal = {
           tol = 0.74
         }, 
         stop("ERROR: 'epsilon.method' not set to a valid option")
  )
  
  ranges = rep(tol, ncol(X))
  names(ranges) = names(X)
  print(ranges)
  
  # conduct equiv test for each variable
  tests = do.call("rbind", lapply(names(X), function(var) {
    print(var)
    
    res = equiv.t.test(X[Tr == 1, var], X[Tr == 0, var], epsilon = ranges[var], std.err = std.err, cluster.x = cluster.x, cluster.y = cluster.y)
    res$stat = res$t.stat
    res$obs_diff = (mean(X[Tr == 1, var], na.rm = TRUE) - mean(X[Tr == 0, var], na.rm = TRUE))
    res$obs_smd = ((mean(X[Tr == 1, var], na.rm = TRUE) - mean(X[Tr == 0, var], na.rm = TRUE))) / sd(X[Tr == 0, var], na.rm = TRUE)
    res$sd = sd(X[Tr == 0, var], na.rm = TRUE)
      
      return(c(res$inverted
               , round(res$p, 4)
               , res$obs_smd
               , res$obs_diff
               , res$power
               , res$sd))
    
  }))
  
  p.vals = unlist(tests[,2])
  names(p.vals) = names(ranges)
  
  power = unlist(tests[,5])
  names(power) = names(ranges)
  
  inverted = unlist(tests[,1])
  names(inverted) = names(ranges)
  
  sd = unlist(tests[,6])
  names(sd) = names(ranges)
  
  # return to scale of var
  inverted.scaled = unlist(lapply(names(inverted), function(var) {
    return(inverted[var] * sd[var])
  }))
  names(inverted.scaled) = names(ranges)
  
  observed.smd = unlist(tests[,3])
  names(observed.smd) = names(ranges)
  
  observed.diff = unlist(tests[,4])
  names(observed.diff) = names(ranges)
  
  # conduct BH FDR adjustment
  if(fdr_correct) {
    p.vals = p.adjust(p.vals, method = "BH")  
  }
  
  return(list(tol = ranges, inverted = inverted, inverted.scaled = inverted.scaled, p.vals = p.vals, observed.diff = observed.diff, observed.smd = observed.smd, power = power))
}

## a helper function to generate the plot
generate_plot = function(equiv_tests, panel.widths=c(1, 1, 5, 1, 1), display.names = NULL, var.rounding = 1, pval.rounding = 2, fdr_correct = FALSE) {
  .e <- environment()
  if(!is.null(display.names)) {
    equiv_tests$names = factor(display.names, levels = rev(display.names))
  } else {
    equiv_tests$names = factor(row.names(equiv_tests), levels = rev(row.names(equiv_tests)))
  }
  equiv_tests$const = rep(1, nrow(equiv_tests))
  equiv_tests = equiv_tests[nrow(equiv_tests):1, ]
  
  g = ggplot(equiv_tests, aes(x = names) )
  print(length(unique(equiv_tests$tol)))
  g = g + geom_linerange(aes(ymin = -1 * inverted, ymax = inverted), size = 5, color = "darkgray", alpha = 0.9)
  if(length(unique(equiv_tests$tol)) > 1){
    g = g + geom_linerange(aes(ymin = -1 * tol, ymax = tol), size = 10, color = 'gray')   
  } else {
    print("here")
    print(unique(equiv_tests$tol))
    lines = unique(equiv_tests$tol)
    g = g + geom_hline(yintercept = c(-1 * lines, lines), linetype = 2, size = 0.75)
  }
  g = g  + scale_shape_identity() + geom_point(aes(y = observed.smd), color = "black", shape = 18, size = 4)
  g = (g + coord_flip()
       + theme(
         axis.text.y = element_blank()
         , axis.ticks.y = element_blank()
         , axis.title.y = element_blank()
         , axis.text.x = element_text(size = 14)
         , axis.title.x = element_text(size = 14))
       + labs(x=NULL, y = paste("Equivalence Range (in standard deviations \u03C3)"), font=5) + theme_bw()
  )
  if(length(unique(equiv_tests$tol)) == 1) {
    g = g + ggtitle(paste0("Equivalence Tests  \n \n", "Equivalence Range: +/- ", round(unique(equiv_tests$tol), 2), "\u03C3 \n"))
  } else {
    g = g + ggtitle("Equivalence Tests  \n \n \n")
  }
  
  g_inv = ggplot(equiv_tests, aes(x = names, y = const, label = round(inverted.scaled, var.rounding)), environment = .e)
  g_inv = g_inv + geom_text()
  g_inv = (g_inv + theme_bw() + coord_flip()
           + theme(panel.grid.minor=element_blank()
                   , panel.grid.major=element_blank()
                   #, axis.line.x = element_blank()
                   , axis.text.x = element_text(color = "white", size = 14)
                   , axis.ticks.x = element_line(color = "white")
                   , axis.text.y = element_blank()
                   , axis.ticks.y = element_blank()
                   , axis.title.x = element_text(size = 14)
           )
           + ylim(1-.05, 1.05)
           + ggtitle("Equivalence\nConfidence\nInterval (+/-)\n(Scale of Var)")
           + labs(y = " ", x = NULL)
  )
  
  g_obs = ggplot(equiv_tests, aes(x = names, y = const, label = round(observed.diff, var.rounding)), environment = .e)
  g_obs = g_obs + geom_text()
  g_obs = (g_obs + theme_bw() + coord_flip()
           + theme(panel.grid.minor=element_blank()
                   , panel.grid.major=element_blank()
                   #, axis.line.x = element_blank()
                   , axis.text.x = element_text(color = "white", size = 14)
                   , axis.ticks.x = element_line(color = "white")
                   , axis.text.y = element_blank()
                   , axis.ticks.y = element_blank()
                   , axis.title.x = element_text(size = 14)
           )
           + ylim(1-.05, 1.05)
           + ggtitle("Observed\nMean\nDifference\n(Scale of Var)")
           + labs(y = " ", x = NULL)
  )
  
  g_pval = ggplot(equiv_tests, aes(x = names, y = const, label = round(p.vals, pval.rounding)), environment = .e)
  g_pval = g_pval + geom_text()
  g_pval = (g_pval + theme_bw() + coord_flip()
            + theme(panel.grid.minor=element_blank()
                    , panel.grid.major=element_blank()
                    #, axis.line.x = element_blank()
                    , axis.text.x = element_text(color = "white", size = 14)
                    , axis.ticks.x = element_line(color = "white")
                    , axis.text.y = element_blank()
                    , axis.ticks.y = element_blank()
                    , axis.title.x = element_text(size = 14)
            )
            + ylim(1-.05, 1.05)
            + ggtitle(ifelse(fdr_correct, "\nFDR\nCorrected\nP-value", "\n\n\nP-value"))
            + labs(y = " ", x = NULL)
  )
  
  g_var = ggplot(equiv_tests, aes(x = names, y = const, label = names))
  g_var = g_var + geom_text()
  g_var = (g_var + theme_bw() + coord_flip()
           + theme(panel.grid.minor=element_blank()
                   , panel.grid.major=element_blank()
                   #, axis.line.x = element_blank()
                   , axis.text.x = element_text(color = "white", size = 14)
                   , axis.ticks.x = element_line(color = "white")
                   , axis.text.y = element_blank()
                   , axis.ticks.y = element_blank()
                   , panel.border = element_blank()
                   , axis.title.x = element_text(size = 14)
           )
           + ylim(1-.05, 1.05)
           + ggtitle("\n \n \nVariable") + theme(plot.title = element_text(hjust = 0.5))
           + labs(y = " ", x = NULL)
  )
  
  grid.arrange(g_var, g_obs, g, g_inv, g_pval, ncol=5, nrow=1, widths= panel.widths, heights=c(4))
}

```

### Figure B.3

```{r warning=FALSE, message=FALSE, fig.width=13, fig.height=7.5}

ess2 = ess %>%
  dplyr::select("Religiosity", "Member_discrgroup", "Country_citizen", "Born_country", "Ethnic_minority", "Sex", "Age", "Education_highest", "Paidwork_7days", "Educ_7days", "Unempl_7days", "Retired_7days", "Disabled_sick_7days", "Housework_7days", "Type_org", "Income_source", "Total_income", "Income_subjective", "Marital_status", "Mobile_phone", "Residence", "Post", "Turnout_yes", "Partisanship_yes", "IncumbentPM_vote") %>%
  as.data.frame()

ess2[,1:25] <- sapply(ess2[,1:25],as.numeric)

# For the balance checks, we employ the code from Hartman and Hidalgo (2018)

replicate_strict = as.data.frame(run_equiv(X = subset(ess2, select = c("Religiosity", "Member_discrgroup", "Country_citizen", "Born_country", "Ethnic_minority", "Sex", "Age", "Education_highest", "Paidwork_7days", "Educ_7days", "Unempl_7days", "Retired_7days", "Disabled_sick_7days", "Housework_7days", "Type_org", "Income_source", "Total_income", "Income_subjective", "Marital_status", "Mobile_phone", "Residence", "Turnout_yes", "Partisanship_yes", "IncumbentPM_vote")), 
                                           Tr = ess2$Post, epsilon.method = "custom", custom.epsilon = 0.36,
                                           fdr_correct = TRUE))

g1 <- generate_plot(replicate_strict, panel.widths = c(2.5, 1.25, 5, 1.2, 1.2), 
                    display.names = c("Religiosity", "Member of discriminated group", "Citizen of the country", "Born in the country", "Ethnic minority", "Sex", "Age", "Education", "Paid work (past 7days)", "Education (past 7days)", "Unemployed (past 7days)", "Retired (past 7days)", "Disabled/sick (past 7days)", "Housework (past 7days)", "Organization of employment", "Income source", "Total household income", "Income (subjective)", "Marital status", "Mobile phone", "Residence", "Turnout", "Partisanship", "Incumbent vote"), 
                    pval.rounding = 3, fdr_correct = TRUE)

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigB3_ESS_Balance.png", g1, dpi = 600, width = 13, height = 7.5, unit = "in")

```

## Appendix C

### Table C.1

```{r results='asis'}

tabc1 = list()

tabc1[[1]] = lm(data = ess, weights = Weights, Econ_sat ~ Post + factor(cntry))

tabc1[[2]] = lm(data = ess, weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabc1[[3]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + factor(cntry))

tabc1[[4]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabc1[[5]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + factor(cntry))

tabc1[[6]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabc1[[7]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + factor(cntry))

tabc1[[8]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabc1[[9]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + factor(cntry))

tabc1[[10]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc1, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (all countries)")
#cat('</div>')

```

### Table C.2

```{r results='asis'}

tabc2 = list()

tabc2[[1]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Econ_sat ~ Post)

tabc2[[2]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc2[[3]] = lm(data = dplyr::filter(ess, (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post)

tabc2[[4]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc2[[5]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post)

tabc2[[6]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc2[[7]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post)

tabc2[[8]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc2[[9]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post)

tabc2[[10]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc2, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (Switzerland)")
#cat('</div>')

```

### Table C.3

```{r results='asis'}

tabc3 = list()

tabc3[[1]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Econ_sat ~ Post)

tabc3[[2]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc3[[3]] = lm(data = dplyr::filter(ess, (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post)

tabc3[[4]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc3[[5]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post)

tabc3[[6]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc3[[7]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post)

tabc3[[8]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc3[[9]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post)

tabc3[[10]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc3, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (Germany)")
#cat('</div>')

```

### Table C.4

```{r results='asis'}

tabc4 = list()

tabc4[[1]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Econ_sat ~ Post)

tabc4[[2]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc4[[3]] = lm(data = dplyr::filter(ess, (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post)

tabc4[[4]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc4[[5]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post)

tabc4[[6]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc4[[7]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post)

tabc4[[8]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc4[[9]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post)

tabc4[[10]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc4, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (Spain)")
#cat('</div>')

```

### Table C.5

```{r results='asis'}

tabc5 = list()

tabc5[[1]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Econ_sat ~ Post)

tabc5[[2]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc5[[3]] = lm(data = dplyr::filter(ess, (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post)

tabc5[[4]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc5[[5]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post)

tabc5[[6]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc5[[7]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post)

tabc5[[8]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc5[[9]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post)

tabc5[[10]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc5, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (the United Kingdom)")
#cat('</div>')

```

### Table C.6

```{r results='asis'}

tabc6 = list()

tabc6[[1]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Econ_sat ~ Post)

tabc6[[2]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc6[[3]] = lm(data = dplyr::filter(ess, (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post)

tabc6[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc6[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post)

tabc6[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc6[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post)

tabc6[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc6[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post)

tabc6[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc6, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (the Netherlands)")
#cat('</div>')

```

### Table C.7

```{r results='asis'}

tabc7 = list()

tabc7[[1]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Econ_sat ~ Post)

tabc7[[2]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc7[[3]] = lm(data = dplyr::filter(ess, (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post)

tabc7[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc7[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post)

tabc7[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc7[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post)

tabc7[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabc7[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post)

tabc7[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc7, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (Norway)")
#cat('</div>')

```

### Table C.8

```{r results='asis'}

tabc8 = list()

tabc8[[1]] = lm(data = ess, weights = Weights, Econ_sat ~ Post + factor(cntry))

tabc8[[2]] = lm(data = ess, weights = Weights, Econ_sat ~ Post + Linear_trend + factor(cntry))

tabc8[[3]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Econ_sat ~ Post)

tabc8[[4]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Econ_sat ~ Post + Linear_trend)

tabc8[[5]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Econ_sat ~ Post)

tabc8[[6]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Econ_sat ~ Post + Linear_trend)

tabc8[[7]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Econ_sat ~ Post)

tabc8[[8]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Econ_sat ~ Post + Linear_trend)

tabc8[[9]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Econ_sat ~ Post)

tabc8[[10]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Econ_sat ~ Post + Linear_trend)

tabc8[[11]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Econ_sat ~ Post)

tabc8[[12]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Econ_sat ~ Post + Linear_trend)

tabc8[[13]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Econ_sat ~ Post)

tabc8[[14]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Econ_sat ~ Post + Linear_trend)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabc8, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full", "Full", "CH", "CH", "DE", "DE", "ES", "ES", "UK", "UK", "NL", "NL", "NO", "NO"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview", "Linear trend"), reorder.coef = c(2, 3, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national economy (0-10). All models use survey weights.", caption = "Satisfaction with the national economy (linear trend)")
#cat('</div>')

```

### Figure C.1

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Econ_sat ~ Post + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-1,0.5,0.1), limits = c(-1,0.5), labels = label_number(accuracy = 0.1)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national economy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigC1_ESS_Econsat_incremental_nocontrols.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure C.2

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_after = No_days - 1)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  labs(x = "Number of days after the Lehman Brothers announcement", y = "Satisfaction with the national economy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
# ggsave("Plots/FigC2_ESS_Econsat_incremental_controls_alt.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure C.3

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Econ_sat ~ Post + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_after = No_days - 1)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  labs(x = "Number of days after the Lehman Brothers announcement", y = "Satisfaction with the national economy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
# ggsave("Plots/FigC3_ESS_Econsat_incremental_nocontrols_alt.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure C.4

```{r warning=FALSE, fig.width=20, fig.height=15}

# Define the target date
target_date <- as.Date("2008-09-15")

# Define the list of countries
country <- c("CH", "DE", "ES", "GB", "NL", "NO")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  for (j in 1:6) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  cont = country[j]
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date) %>%
    filter(cntry %in% cont)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Econ_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                              Coefficient = unlist(coefficient_list),
                              CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                              CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                              CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                              CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
  mutate(Date2 = substr(names(coefficient_list), 1, 21)) %>%
  mutate(Country = word(Date, 3, sep=" "),
         Date_start = as.Date(substr(Date2,1,10)),
         Date_end = as.Date(str_sub(Date2,start = -10)),
         No_days = Date_end - Date_start + 1,
         Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  facet_wrap(~Country, nrow = 3, scales = "free", labeller = labeller(Country = c("CH" = "Switzerland", "DE" = "Germany", "ES" = "Spain", "GB" = "United Kingdom", "NL" = "Netherlands", "NO" = "Norway"))) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national economy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigC4_ESS_Econsat_incremental_country_controls_v2.pdf", dpi = 1200, width = 20, height = 15, unit = "in")

```

### Figure C.5

```{r warning=FALSE, fig.width=20, fig.height=15}

# Define the target date
target_date <- as.Date("2008-09-15")

# Define the list of countries
country <- c("CH", "DE", "ES", "GB", "NL", "NO")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  for (j in 1:6) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  cont = country[j]
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date) %>%
    filter(cntry %in% cont)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Econ_sat ~ Post, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                              Coefficient = unlist(coefficient_list),
                              CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                              CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                              CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                              CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
  mutate(Date2 = substr(names(coefficient_list), 1, 21)) %>%
  mutate(Country = word(Date, 3, sep=" "),
         Date_start = as.Date(substr(Date2,1,10)),
         Date_end = as.Date(str_sub(Date2,start = -10)),
         No_days = Date_end - Date_start + 1,
         Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  facet_wrap(~Country, nrow = 3, scales = "free", labeller = labeller(Country = c("CH" = "Switzerland", "DE" = "Germany", "ES" = "Spain", "GB" = "United Kingdom", "NL" = "Netherlands", "NO" = "Norway"))) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national economy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigC5_ESS_Econsat_incremental_country_nocontrols_v2.pdf", dpi = 1200, width = 20, height = 15, unit = "in")

```

## Appendix D

### Table D.1

```{r results='asis'}

tabd1 = list()

tabd1[[1]] = lm(data = ess, weights = Weights, Likely_unempl ~ Post + factor(cntry))

tabd1[[2]] = lm(data = ess, weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd1[[3]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + factor(cntry))

tabd1[[4]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd1[[5]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + factor(cntry))

tabd1[[6]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd1[[7]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + factor(cntry))

tabd1[[8]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd1[[9]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + factor(cntry))

tabd1[[10]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd1, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of becoming unemployed (binary). All models use survey weights.", caption = "Likelihood of becoming unemployed (all countries)")
#cat('</div>')

```

### Table D.2

```{r results='asis'}

tabd2 = list()

tabd2[[1]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Likely_unempl ~ Post)

tabd2[[2]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd2[[3]] = lm(data = dplyr::filter(ess, (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post)

tabd2[[4]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd2[[5]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post)

tabd2[[6]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd2[[7]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post)

tabd2[[8]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd2[[9]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post)

tabd2[[10]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd2, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of becoming unemployed (binary). All models use survey weights.", caption = "Likelihood of becoming unemployed (Switzerland)")
#cat('</div>')

```

### Table D.3

```{r results='asis'}

tabd3 = list()

tabd3[[1]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Likely_unempl ~ Post)

tabd3[[2]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd3[[3]] = lm(data = dplyr::filter(ess, (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post)

tabd3[[4]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd3[[5]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post)

tabd3[[6]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd3[[7]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post)

tabd3[[8]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd3[[9]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post)

tabd3[[10]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd3, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of becoming unemployed (binary). All models use survey weights.", caption = "Likelihood of becoming unemployed (Germany)")
#cat('</div>')

```

### Table D.4

```{r results='asis'}

tabd4 = list()

tabd4[[1]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Likely_unempl ~ Post)

tabd4[[2]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd4[[3]] = lm(data = dplyr::filter(ess, (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post)

tabd4[[4]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd4[[5]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post)

tabd4[[6]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd4[[7]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post)

tabd4[[8]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd4[[9]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post)

tabd4[[10]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd4, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of becoming unemployed (binary). All models use survey weights.", caption = "Likelihood of becoming unemployed (Spain)")
#cat('</div>')

```

### Table D.5

```{r results='asis'}

tabd5 = list()

tabd5[[1]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Likely_unempl ~ Post)

tabd5[[2]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd5[[3]] = lm(data = dplyr::filter(ess, (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post)

tabd5[[4]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd5[[5]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post)

tabd5[[6]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd5[[7]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post)

tabd5[[8]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd5[[9]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post)

tabd5[[10]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd5, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of becoming unemployed (binary). All models use survey weights.", caption = "Likelihood of becoming unemployed (the United Kingdom)")
#cat('</div>')

```

### Table D.6

```{r results='asis'}

tabd6 = list()

tabd6[[1]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Likely_unempl ~ Post)

tabd6[[2]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd6[[3]] = lm(data = dplyr::filter(ess, (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post)

tabd6[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd6[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post)

tabd6[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd6[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post)

tabd6[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd6[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post)

tabd6[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd6, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of becoming unemployed (binary). All models use survey weights.", caption = "Likelihood of becoming unemployed (the Netherlands)")
#cat('</div>')

```

### Table D.7

```{r results='asis'}

tabd7 = list()

tabd7[[1]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Likely_unempl ~ Post)

tabd7[[2]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd7[[3]] = lm(data = dplyr::filter(ess, (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post)

tabd7[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd7[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post)

tabd7[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd7[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post)

tabd7[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd7[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post)

tabd7[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd7, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of becoming unemployed (binary). All models use survey weights.", caption = "Likelihood of becoming unemployed (Norway)")
#cat('</div>')

```

### Figure D.1

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.1, 0.2, 0.1), limits = c(-0.1, 0.2)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Unemployment likelihood\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigD1_ESS_Likelyunempl_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure D.2

```{r warning=FALSE, fig.width=20, fig.height=15}

# Define the target date
target_date <- as.Date("2008-09-15")

# Define the list of countries
country <- c("CH", "DE", "ES", "GB", "NL", "NO")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  for (j in 1:6) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  cont = country[j]
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date) %>%
    filter(cntry %in% cont)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Likely_unempl ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                              Coefficient = unlist(coefficient_list),
                              CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                              CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                              CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                              CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
  mutate(Date2 = substr(names(coefficient_list), 1, 21)) %>%
  mutate(Country = word(Date, 3, sep=" "),
         Date_start = as.Date(substr(Date2,1,10)),
         Date_end = as.Date(str_sub(Date2,start = -10)),
         No_days = Date_end - Date_start + 1,
         Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  facet_wrap(~Country, nrow = 3, scales = "free", labeller = labeller(Country = c("CH" = "Switzerland", "DE" = "Germany", "ES" = "Spain", "GB" = "United Kingdom", "NL" = "Netherlands", "NO" = "Norway"))) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Unemployment likelihood\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigD2_ESS_Likely_unempl_incremental_country_controls_v2.pdf", dpi = 1200, width = 20, height = 15, unit = "in")

```

### Table D.8

```{r results='asis'}

tabd8 = list()

tabd8[[1]] = lm(data = ess, weights = Weights, Likely_notenough_money ~ Post + factor(cntry))

tabd8[[2]] = lm(data = ess, weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd8[[3]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + factor(cntry))

tabd8[[4]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd8[[5]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + factor(cntry))

tabd8[[6]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd8[[7]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + factor(cntry))

tabd8[[8]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabd8[[9]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + factor(cntry))

tabd8[[10]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd8, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of not having enough money for household necessities for the next 12 months (binary). All models use survey weights.", caption = "Likelihood of not having enough money for household necessities for the next 12 months (all countries)")
#cat('</div>')

```

### Table D.9

```{r results='asis'}

tabd9 = list()

tabd9[[1]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Likely_notenough_money ~ Post)

tabd9[[2]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd9[[3]] = lm(data = dplyr::filter(ess, (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post)

tabd9[[4]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd9[[5]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post)

tabd9[[6]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd9[[7]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post)

tabd9[[8]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd9[[9]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post)

tabd9[[10]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd9, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of not having enough money for household necessities for the next 12 months (binary). All models use survey weights.", caption = "Likelihood of not having enough money for household necessities for the next 12 months (Switzerland)")
#cat('</div>')

```

### Table D.10

```{r results='asis'}

tabd10 = list()

tabd10[[1]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Likely_notenough_money ~ Post)

tabd10[[2]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd10[[3]] = lm(data = dplyr::filter(ess, (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post)

tabd10[[4]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd10[[5]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post)

tabd10[[6]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd10[[7]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post)

tabd10[[8]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd10[[9]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post)

tabd10[[10]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd10, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of not having enough money for household necessities for the next 12 months (binary). All models use survey weights.", caption = "Likelihood of not having enough money for household necessities for the next 12 months (Germany)")
#cat('</div>')

```

### Table D.11

```{r results='asis'}

tabd11 = list()

tabd11[[1]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Likely_notenough_money ~ Post)

tabd11[[2]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd11[[3]] = lm(data = dplyr::filter(ess, (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post)

tabd11[[4]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd11[[5]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post)

tabd11[[6]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd11[[7]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post)

tabd11[[8]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd11[[9]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post)

tabd11[[10]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd11, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of not having enough money for household necessities for the next 12 months (binary). All models use survey weights.", caption = "Likelihood of not having enough money for household necessities for the next 12 months (Spain)")
#cat('</div>')

```

### Table D.12

```{r results='asis'}

tabd12 = list()

tabd12[[1]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Likely_notenough_money ~ Post)

tabd12[[2]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd12[[3]] = lm(data = dplyr::filter(ess, (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post)

tabd12[[4]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd12[[5]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post)

tabd12[[6]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd12[[7]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post)

tabd12[[8]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd12[[9]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post)

tabd12[[10]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd12, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of not having enough money for household necessities for the next 12 months (binary). All models use survey weights.", caption = "Likelihood of not having enough money for household necessities for the next 12 months (the United Kingdom)")
#cat('</div>')

```

### Table D.13

```{r results='asis'}

tabd13 = list()

tabd13[[1]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Likely_notenough_money ~ Post)

tabd13[[2]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd13[[3]] = lm(data = dplyr::filter(ess, (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post)

tabd13[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd13[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post)

tabd13[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd13[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post)

tabd13[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd13[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post)

tabd13[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd13, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of not having enough money for household necessities for the next 12 months (binary). All models use survey weights.", caption = "Likelihood of not having enough money for household necessities for the next 12 months (the Netherlands)")
#cat('</div>')

```

### Table D.14

```{r results='asis'}

tabd14 = list()

tabd14[[1]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Likely_notenough_money ~ Post)

tabd14[[2]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd14[[3]] = lm(data = dplyr::filter(ess, (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post)

tabd14[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd14[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post)

tabd14[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd14[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post)

tabd14[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabd14[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post)

tabd14[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabd14, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: likelihood of not having enough money for household necessities for the next 12 months (binary). All models use survey weights.", caption = "Likelihood of not having enough money for household necessities for the next 12 months (Norway)")
#cat('</div>')

```

### Figure D.3

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.1, 0.2, 0.1), limits = c(-0.1, 0.2)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Not enough money likelihood\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigD3_ESS_Likelynotenoughmoney_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure D.4

```{r warning=FALSE, fig.width=20, fig.height=15}

# Define the target date
target_date <- as.Date("2008-09-15")

# Define the list of countries
country <- c("CH", "DE", "ES", "GB", "NL", "NO")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  for (j in 1:6) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  cont = country[j]
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date) %>%
    filter(cntry %in% cont)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Likely_notenough_money ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                              Coefficient = unlist(coefficient_list),
                              CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                              CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                              CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                              CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
  mutate(Date2 = substr(names(coefficient_list), 1, 21)) %>%
  mutate(Country = word(Date, 3, sep=" "),
         Date_start = as.Date(substr(Date2,1,10)),
         Date_end = as.Date(str_sub(Date2,start = -10)),
         No_days = Date_end - Date_start + 1,
         Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  facet_wrap(~Country, nrow = 3, scales = "free", labeller = labeller(Country = c("CH" = "Switzerland", "DE" = "Germany", "ES" = "Spain", "GB" = "United Kingdom", "NL" = "Netherlands", "NO" = "Norway"))) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Not enough money likelihood\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigD4_ESS_Likely_notenough_money_incremental_country_controls_v2.pdf", dpi = 1200, width = 20, height = 15, unit = "in")

```

## Appendix E

### Table E.1

```{r results='asis'}

tabe1 = list()

tabe1[[1]] = lm(data = ess, weights = Weights, Gov_sat ~ Post + factor(cntry))

tabe1[[2]] = lm(data = ess, weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabe1[[3]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + factor(cntry))

tabe1[[4]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabe1[[5]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + factor(cntry))

tabe1[[6]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabe1[[7]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + factor(cntry))

tabe1[[8]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabe1[[9]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + factor(cntry))

tabe1[[10]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabe1, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (all countries)")
#cat('</div>')

```

### Table E.2

```{r results='asis'}

tabe2 = list()

tabe2[[1]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Gov_sat ~ Post)

tabe2[[2]] = lm(data = dplyr::filter(ess, cntry == "CH"), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe2[[3]] = lm(data = dplyr::filter(ess, (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post)

tabe2[[4]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe2[[5]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post)

tabe2[[6]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe2[[7]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post)

tabe2[[8]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe2[[9]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post)

tabe2[[10]] = lm(data = dplyr::filter(ess,  (cntry == "CH") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabe2, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (Switzerland)")
#cat('</div>')

```

### Table E.3

```{r results='asis'}

tabe3 = list()

tabe3[[1]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Gov_sat ~ Post)

tabe3[[2]] = lm(data = dplyr::filter(ess, cntry == "DE"), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe3[[3]] = lm(data = dplyr::filter(ess, (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post)

tabe3[[4]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe3[[5]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post)

tabe3[[6]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe3[[7]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post)

tabe3[[8]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe3[[9]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post)

tabe3[[10]] = lm(data = dplyr::filter(ess,  (cntry == "DE") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabe3, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (Germany)")
#cat('</div>')

```

### Table E.4

```{r results='asis'}

tabe4 = list()

tabe4[[1]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Gov_sat ~ Post)

tabe4[[2]] = lm(data = dplyr::filter(ess, cntry == "ES"), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe4[[3]] = lm(data = dplyr::filter(ess, (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post)

tabe4[[4]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe4[[5]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post)

tabe4[[6]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe4[[7]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post)

tabe4[[8]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe4[[9]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post)

tabe4[[10]] = lm(data = dplyr::filter(ess,  (cntry == "ES") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabe4, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (Spain)")
#cat('</div>')

```

### Table E.5

```{r results='asis'}

tabe5 = list()

tabe5[[1]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Gov_sat ~ Post)

tabe5[[2]] = lm(data = dplyr::filter(ess, cntry == "GB"), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe5[[3]] = lm(data = dplyr::filter(ess, (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post)

tabe5[[4]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe5[[5]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post)

tabe5[[6]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe5[[7]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post)

tabe5[[8]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe5[[9]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post)

tabe5[[10]] = lm(data = dplyr::filter(ess,  (cntry == "GB") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabe5, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (the United Kingdom)")
#cat('</div>')

```

### Table E.6

```{r results='asis'}

tabe6 = list()

tabe6[[1]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Gov_sat ~ Post)

tabe6[[2]] = lm(data = dplyr::filter(ess, cntry == "NL"), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe6[[3]] = lm(data = dplyr::filter(ess, (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post)

tabe6[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe6[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post)

tabe6[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe6[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post)

tabe6[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe6[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post)

tabe6[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NL") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabe6, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (the Netherlands)")
#cat('</div>')

```

### Table E.7

```{r results='asis'}

tabe7 = list()

tabe7[[1]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Gov_sat ~ Post)

tabe7[[2]] = lm(data = dplyr::filter(ess, cntry == "NO"), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe7[[3]] = lm(data = dplyr::filter(ess, (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post)

tabe7[[4]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe7[[5]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post)

tabe7[[6]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe7[[7]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post)

tabe7[[8]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

tabe7[[9]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post)

tabe7[[10]] = lm(data = dplyr::filter(ess,  (cntry == "NO") & (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabe7, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (Norway)")
#cat('</div>')

```

### Figure E.1

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Gov_sat ~ Post + Sex + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national government\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigE1_ESS_Govsat_incremental_nocontrols.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure E.2

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_after = No_days - 1)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  labs(x = "Number of days after the Lehman Brothers announcement", y = "Satisfaction with the national government\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigE2_ESS_Govsat_incremental_controls_alt.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure E.3

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Gov_sat ~ Post + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_after = No_days - 1)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  labs(x = "Number of days after the Lehman Brothers announcement", y = "Satisfaction with the national government\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigE3_ESS_Govsat_incremental_nocontrols_alt.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure E.4

```{r warning=FALSE, fig.width=20, fig.height=15}

# Define the target date
target_date <- as.Date("2008-09-15")

# Define the list of countries
country <- c("CH", "DE", "ES", "GB", "NL", "NO")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  for (j in 1:6) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  cont = country[j]
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date) %>%
    filter(cntry %in% cont)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Gov_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                              Coefficient = unlist(coefficient_list),
                              CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                              CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                              CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                              CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
  mutate(Date2 = substr(names(coefficient_list), 1, 21)) %>%
  mutate(Country = word(Date, 3, sep=" "),
         Date_start = as.Date(substr(Date2,1,10)),
         Date_end = as.Date(str_sub(Date2,start = -10)),
         No_days = Date_end - Date_start + 1,
         Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  facet_wrap(~Country, nrow = 3, scales = "free", labeller = labeller(Country = c("CH" = "Switzerland", "DE" = "Germany", "ES" = "Spain", "GB" = "United Kingdom", "NL" = "Netherlands", "NO" = "Norway"))) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national government\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigE4_ESS_Govsat_incremental_country_controls_v2.pdf", dpi = 1200, width = 20, height = 15, unit = "in")

```

### Figure E.5

```{r warning=FALSE, fig.width=20, fig.height=15}

# Define the target date
target_date <- as.Date("2008-09-15")

# Define the list of countries
country <- c("CH", "DE", "ES", "GB", "NL", "NO")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  for (j in 1:6) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  cont = country[j]
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date) %>%
    filter(cntry %in% cont)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Gov_sat ~ Post, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date), as.character(cont))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                              Coefficient = unlist(coefficient_list),
                              CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                              CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                              CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                              CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
  mutate(Date2 = substr(names(coefficient_list), 1, 21)) %>%
  mutate(Country = word(Date, 3, sep=" "),
         Date_start = as.Date(substr(Date2,1,10)),
         Date_end = as.Date(str_sub(Date2,start = -10)),
         No_days = Date_end - Date_start + 1,
         Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  facet_wrap(~Country, nrow = 3, scales = "free", labeller = labeller(Country = c("CH" = "Switzerland", "DE" = "Germany", "ES" = "Spain", "GB" = "United Kingdom", "NL" = "Netherlands", "NO" = "Norway"))) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the national government\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigE5_ESS_Govsat_incremental_country_nocontrols_v2.pdf", dpi = 1200, width = 20, height = 15, unit = "in")

```

## Appendix F

### Table F.1

```{r results='asis'}

tabf1 = list()

tabf1[[1]] = lm(data = ess, weights = Weights, Trust_parties ~ Post + factor(cntry))

tabf1[[2]] = lm(data = ess, weights = Weights, Trust_parties ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf1[[3]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Trust_parties ~ Post + factor(cntry))

tabf1[[4]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Trust_parties ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf1[[5]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Trust_parties ~ Post + factor(cntry))

tabf1[[6]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Trust_parties ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf1[[7]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Trust_parties ~ Post + factor(cntry))

tabf1[[8]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Trust_parties ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf1[[9]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Trust_parties ~ Post + factor(cntry))

tabf1[[10]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Trust_parties ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabf1, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: trust in political parties (0-10). All models use survey weights.", caption = "Trust in political parties (all countries)")
#cat('</div>')

```

### Table F.2

```{r results='asis'}

tabf2 = list()

tabf2[[1]] = lm(data = ess, weights = Weights, Trust_Parliament ~ Post + factor(cntry))

tabf2[[2]] = lm(data = ess, weights = Weights, Trust_Parliament ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf2[[3]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Trust_Parliament ~ Post + factor(cntry))

tabf2[[4]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Trust_Parliament ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf2[[5]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Trust_Parliament ~ Post + factor(cntry))

tabf2[[6]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Trust_Parliament ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf2[[7]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Trust_Parliament ~ Post + factor(cntry))

tabf2[[8]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Trust_Parliament ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf2[[9]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Trust_Parliament ~ Post + factor(cntry))

tabf2[[10]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Trust_Parliament ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabf2, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: trust in the national Parliament (0-10). All models use survey weights.", caption = "Trust in the national Parliament (all countries)")
#cat('</div>')

```

### Table F.3

```{r results='asis'}

tabf3 = list()

tabf3[[1]] = lm(data = ess, weights = Weights, Trust_politicians ~ Post + factor(cntry))

tabf3[[2]] = lm(data = ess, weights = Weights, Trust_politicians ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf3[[3]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Trust_politicians ~ Post + factor(cntry))

tabf3[[4]] = lm(data = dplyr::filter(ess, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Trust_politicians ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf3[[5]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Trust_politicians ~ Post + factor(cntry))

tabf3[[6]] = lm(data = dplyr::filter(ess, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Trust_politicians ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf3[[7]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Trust_politicians ~ Post + factor(cntry))

tabf3[[8]] = lm(data = dplyr::filter(ess, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Trust_politicians ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabf3[[9]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Trust_politicians ~ Post + factor(cntry))

tabf3[[10]] = lm(data = dplyr::filter(ess, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Trust_politicians ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabf3, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: trust in politicians (0-10). All models use survey weights.", caption = "Trust in politicians (all countries)")
#cat('</div>')

```

### Figure F.1

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Trust_parties ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.5, 0.5, 0.1), limits = c(-0.5, 0.5)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Trust in political parties\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigF1_ESS_Trustparties_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure F.2

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Trust_Parliament ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.5, 1, 0.1), limits = c(-0.5, 1)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Trust in Parliament\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigF2_ESS_Trustparliament_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure F.3

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Trust_politicians ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.5, 0.5, 0.1), limits = c(-0.5, 0.5)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Trust in politicians\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigF3_ESS_Trustpoliticians_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

## Appendix G

### Figure G.1

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Edu_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.6, 0.4, 0.1), limits = c(-0.6, 0.4), labels = scales::label_number(accuracy = 0.1)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the state of the education\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigG1_ESS_Edusat_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure G.2

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Health_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.4, 0.4, 0.1), limits = c(-0.4, 0.4)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with the state of health services\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigG2_ESS_Healthsat_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure G.3

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Dem_sat ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-1, 0.5, 0.1), limits = c(-1, 0.5)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Satisfaction with democracy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigG3_ESS_Demsat_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure G.4

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Partisanship_yes ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.2, 0.1, 0.1), limits = c(-0.2, 0.1)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Likelihood of being close to a party\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigG4_ESS_Partisanship_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure G.5

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(IncumbentPM_partisan ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.2, 0.2, 0.1), limits = c(-0.2, 0.2)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Likelihood of being close to the Prime-Minister party\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigG5_ESS_PartisanshipPM_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure G.6

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Turnout_yes ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.2, 0.1, 0.1), limits = c(-0.2, 0.1)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Likelihood of turnout in the last election\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigG6_ESS_Turnout_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure G.7

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:90) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(IncumbentPM_vote ~ Post + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.2, 0.1, 0.1), limits = c(-0.2, 0.1)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Reported vote - Prime Minister party\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigG7_ESS_PMparty_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

## Appendix H

### Table H.1

```{r results='asis'}

tabh1 = list()

tabh1[[1]] = lm(data = ess %>% filter(Date < "2008-09-16"), weights = Weights, Econ_sat ~ Placebo + factor(cntry))

tabh1[[2]] = lm(data = ess %>% filter(Date < "2008-09-16"), weights = Weights, Econ_sat ~ Placebo + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

tabh1[[3]] = lm(data = ess %>% filter(Date < "2008-09-16"), weights = Weights, Gov_sat ~ Placebo + factor(cntry))

tabh1[[4]] = lm(data = ess %>% filter(Date < "2008-09-16"), weights = Weights, Gov_sat ~ Placebo + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry))

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabh1, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("All countries", "All countries", "All countries", "All countries"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variables for the models: satisfaction with the national economy (0-10) - models 1-2; satisfaction with the national government (0-10) - models 3-4. All models use survey weights. The sample is restricted to observations collected before 16 September 2008.", caption = "Satisfaction with the national economy and national government (all countries, placebo test, hypothetical Lehman Brothers announcement - 1 September 2008)")
#cat('</div>')

```

### Figure H.1

```{r warning=FALSE, fig.width=15, fig.height=10}

# Restrict data to the observations before September 16
ess1 = ess %>% filter(Date < "2008-09-16")

# Define the target date
target_date <- as.Date("2008-09-01")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:10) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess1 %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Econ_sat ~ Placebo + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Placebo"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Placebo", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Placebo", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  #scale_y_continuous(breaks = seq(-1,0.5,0.25), limits = c(-1,0.5)) +
  labs(x = "Placebo test\nNumber of days before and after\na hypothetical Lehman Brothers announcement\n(1 September 2008)", y = "Satisfaction with the national economy\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigH1_ESS_Econsat_incremental_controls_placebo_1September.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Figure H.2

```{r warning=FALSE, fig.width=15, fig.height=10}

# Restrict data to the observations before September 16
ess1 = ess %>% filter(Date < "2008-09-16")

# Define the target date
target_date <- as.Date("2008-09-01")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:10) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- ess1 %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Gov_sat ~ Placebo + Sex + Age + Education_highest + Residence + Marital_status + Income_subjective + Ethnic_minority + Country_citizen + Paidwork_7days + Unempl_7days + Educ_7days + Retired_7days + Disabled_sick_7days + Housework_7days + Turnout_yes + IncumbentPM_vote + factor(cntry), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Placebo"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Placebo", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Placebo", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  #scale_y_continuous(breaks = seq(-1,0.5,0.25), limits = c(-1,0.5)) +
  labs(x = "Placebo test\nNumber of days before and after\na hypothetical Lehman Brothers announcement\n(1 September 2008)", y = "Satisfaction with the national government\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigH2_ESS_Govsat_incremental_controls_placebo_1September.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

## Appendix I

### Read the Dow Jones Factiva data

```{r}

uk <- read_excel("Data/DowJonesFactiva.xlsx", sheet = "UK") %>% slice_head(n = 12)

nl <- read_excel("Data/DowJonesFactiva.xlsx", sheet = "NL") %>% slice_head(n = 12)

de <- read_excel("Data/DowJonesFactiva.xlsx", sheet = "DE") %>% slice_head(n = 12)

es <- read_excel("Data/DowJonesFactiva.xlsx", sheet = "ES") %>% slice_head(n = 12)

no <- read_excel("Data/DowJonesFactiva.xlsx", sheet = "NO") %>% slice_head(n = 12)

sw <- read_excel("Data/DowJonesFactiva.xlsx", sheet = "SW") %>% slice_head(n = 12)

```

### Recode the Dow Jones Factiva data

```{r}

uk = mutate(uk, Month = as.Date(as.numeric(Month), origin = "1899-12-30"))

nl = mutate(nl, Month = as.Date(as.numeric(Month), origin = "1899-12-30"))

de = mutate(de, Month = as.Date(as.numeric(Month), origin = "1899-12-30"))

es = mutate(es, Month = as.Date(as.numeric(Month), origin = "1899-12-30"))

no = mutate(no, Month = as.Date(as.numeric(Month), origin = "1899-12-30"))

sw = mutate(sw, Month = as.Date(as.numeric(Month), origin = "1899-12-30"))

```

### Figure I.1

```{r warning=FALSE, fig.width=20, fig.height=30}

# UK

my_colors <- c("Lehman" = "red", "econom*" = "blue", "crisis/crises" = "green")

p1 = uk %>%
  select(Month, Country, Lehman, `econom*`, `crisis/crises`, N)  %>%
  pivot_longer(-c(Month, Country, N), names_to = "Variable", values_to = "Value") %>% 
  group_by(Variable) %>%
  mutate(Prop = Value/N * 100) %>%
  ggplot(aes(x = Month, y = Prop, color = Variable)) +
  geom_point(aes(group = Variable), size = 4) +
  geom_line(aes(group = Variable), linewidth = 1.5) +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
    annotate("text", x = as.Date("2008-07-15"), y = 15, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(date_breaks = "1 month", date_labels = "%b\n%Y") +
  scale_y_continuous(limits = c(0, 20)) +
  labs(x = "", y = "Proportion of monthly articles\nmentioning the term(s) (%)", caption = "Source: Dow Jones Factiva", title = "United Kingdom", color = "Search\nTerm") +
  scale_color_manual(values = my_colors) +
  theme2 +
  theme(legend.position = "top")

# NL

my_colors <- c("Lehman" = "red", "econom*" = "blue", "crisis/crises" = "green")

p2 = nl %>%
  select(Month, Country, Lehman, `econom*`, `crisis/crises`, N)  %>%
  pivot_longer(-c(Month, Country, N), names_to = "Variable", values_to = "Value") %>% 
  group_by(Variable) %>%
  mutate(Prop = Value/N * 100) %>%
  ggplot(aes(x = Month, y = Prop, color = Variable)) +
  geom_point(aes(group = Variable), size = 4) +
  geom_line(aes(group = Variable), linewidth = 1.5) +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
    annotate("text", x = as.Date("2008-07-15"), y = 17, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(date_breaks = "1 month", date_labels = "%b\n%Y") +
  scale_y_continuous(limits = c(0, 20)) +
  labs(x = "", y = "Proportion of monthly articles\nmentioning the term(s) (%)", caption = "Source: Dow Jones Factiva", title = "Netherlands", color = "Search\nTerm") +
  scale_color_manual(values = my_colors) +
  theme2 +
  theme(legend.position = "top")

# DE

my_colors <- c("Lehman" = "red", "Wirtschaft*" = "blue", "Krise/Krisen" = "green")

p3 = de %>%
  select(Month, Country, Lehman, `Wirtschaft*`, `Krise/Krisen`, N)  %>%
  pivot_longer(-c(Month, Country, N), names_to = "Variable", values_to = "Value") %>% 
  group_by(Variable) %>%
  mutate(Prop = Value/N * 100) %>%
  ggplot(aes(x = Month, y = Prop, color = Variable)) +
  geom_point(aes(group = Variable), size = 4) +
  geom_line(aes(group = Variable), linewidth = 1.5) +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
    annotate("text", x = as.Date("2008-07-15"), y = 15, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(date_breaks = "1 month", date_labels = "%b\n%Y") +
  scale_y_continuous(limits = c(0, 20)) +
  labs(x = "", y = "Proportion of monthly articles\nmentioning the term(s) (%)", caption = "Source: Dow Jones Factiva", title = "Germany", color = "Search\nTerm") +
  scale_color_manual(values = my_colors) +
  theme2 +
  theme(legend.position = "top")

# ES

my_colors <- c("Lehman" = "red", "econom*" = "blue", "crisis" = "green")

p4 = es %>%
  select(Month, Country, Lehman, `econom*`, `crisis`, N)  %>%
  pivot_longer(-c(Month, Country, N), names_to = "Variable", values_to = "Value") %>% 
  group_by(Variable) %>%
  mutate(Prop = Value/N * 100) %>%
  ggplot(aes(x = Month, y = Prop, color = Variable)) +
  geom_point(aes(group = Variable), size = 4) +
  geom_line(aes(group = Variable), linewidth = 1.5) +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
    annotate("text", x = as.Date("2008-07-15"), y = 17, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(date_breaks = "1 month", date_labels = "%b\n%Y") +
  scale_y_continuous(limits = c(0, 20)) +
  labs(x = "", y = "Proportion of monthly articles\nmentioning the term(s) (%)", caption = "Source: Dow Jones Factiva", title = "Spain", color = "Search\nTerm") +
  scale_color_manual(values = my_colors) +
  theme2 +
  theme(legend.position = "top")

# NO

my_colors <- c("Lehman" = "red", "økonom*" = "blue", "kris*" = "green")

p5 = no %>%
  select(Month, Country, Lehman, `økonom*`, `kris*`, N)  %>%
  pivot_longer(-c(Month, Country, N), names_to = "Variable", values_to = "Value") %>% 
  group_by(Variable) %>%
  mutate(Prop = Value/N * 100) %>%
  ggplot(aes(x = Month, y = Prop, color = Variable)) +
  geom_point(aes(group = Variable), size = 4) +
  geom_line(aes(group = Variable), linewidth = 1.5) +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
    annotate("text", x = as.Date("2008-07-15"), y = 17, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(date_breaks = "1 month", date_labels = "%b\n%Y") +
  scale_y_continuous(limits = c(0, 20)) +
  labs(x = "", y = "Proportion of monthly articles\nmentioning the term(s) (%)", caption = "Source: Dow Jones Factiva", title = "Norway", color = "Search\nTerm") +
  scale_color_manual(values = my_colors) +
  theme2 +
  theme(legend.position = "top")

# SW

my_colors <- c("Lehman" = "red", "Wirtschaft*" = "blue", "Krise/Krisen" = "green")

p6 = sw %>%
  select(Month, Country, Lehman, `Wirtschaft*`, `Krise/Krisen`, N)  %>%
  pivot_longer(-c(Month, Country, N), names_to = "Variable", values_to = "Value") %>% 
  group_by(Variable) %>%
  mutate(Prop = Value/N * 100) %>%
  ggplot(aes(x = Month, y = Prop, color = Variable)) +
  geom_point(aes(group = Variable), size = 4) +
  geom_line(aes(group = Variable), linewidth = 1.5) +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
    annotate("text", x = as.Date("2008-07-15"), y = 17, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(date_breaks = "1 month", date_labels = "%b\n%Y") +
  scale_y_continuous(limits = c(0, 20)) +
  labs(x = "", y = "Proportion of monthly articles\nmentioning the term(s) (%)", caption = "Source: Dow Jones Factiva", title = "Switzerland", color = "Search\nTerm") +
  scale_color_manual(values = my_colors) +
  theme2 +
  theme(legend.position = "top")

p1 + p2 + p3 + p4 + p5 + p6 + plot_layout(ncol = 2)

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigI1_Factiva.pdf", dpi = 1200, width = 20, height = 30, unit = "in")

```

### Read the ParlSpeech dataset

```{r}

# We employ data from the ParlSpeech dataset (Rauh and Schwalbach 2020) - https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/L4OAKN

uk = readRDS("Data/Corp_HouseOfCommons_V2.rds")
nl = readRDS("Data/Corp_TweedeKamer_V2.rds")
de = readRDS("Data/Corp_Bundestag_V2.rds")
es = readRDS("Data/Corp_Congreso_V2.rds")

```

### Filter the ParlSpeech dataset

```{r}

# Filter dataset for year 2008

## UK
uk = mutate(uk, date = as.Date(date, format = "%Y-%m-%d"))
uk = uk %>% filter(format(date, "%Y") == "2008")

## NL
nl = mutate(nl, date = as.Date(date, format = "%Y-%m-%d"))
nl = nl %>% filter(format(date, "%Y") == "2008")

## Germany
de = mutate(de, date = as.Date(date, format = "%Y-%m-%d"))
de = de %>% filter(format(date, "%Y") == "2008")

## Spain
es = mutate(es, date = as.Date(date, format = "%Y-%m-%d"))
es = es %>% filter(format(date, "%Y") == "2008")

```

### Recode the ParlSpeech dataset

```{r}

# UK

terms <- c("Lehman", "econom(y|ic|ical)", "crisis(es)?") 

uk = mutate(uk,
            
            # Period - pre vs. post-Lehman
            Post = ifelse(date <= "2008-09-15", 0, 1),
            
            # Incumbent party
            Gov = ifelse(party %in% "Lab", 1, 0),
            
            # Sentiment analysis
            sentiment = get_sentiment(text, method = "nrc", lang = "english"),
            sentiment3 = sentiment/terms)

uk <- uk %>%
  mutate(
    !!!setNames(
      lapply(terms, function(term) str_count(.$text, regex(term, ignore_case = TRUE))),
      paste0("count_", gsub("[^a-zA-Z]", "", terms))
    ),
    
    total_count = count_Lehman + count_economyicical + count_crisises)

# NL

terms_dutch <- c(
  "Lehman",                     # Same term as in English
  "econom(ie|isch|ische)",      # Dutch terms for economy/economic (economy, economical)
  "crisis(esen)?"               # Dutch for crisis/crises
)

nl = mutate(nl,
            
            # Period - pre vs. post-Lehman
            Post = ifelse(date <= "2008-09-15", 0, 1),
            
            # Incumbent parties
            Gov = ifelse(party %in% c("CDA", "PvdA", "CU"), 1, 0),
            
            # Sentiment analysis
            sentiment = get_sentiment(text, method = "nrc", lang = "dutch"),
            sentiment3 = sentiment/terms)

nl <- nl %>%
  mutate(
    !!!setNames(
      lapply(terms_dutch, function(term) str_count(.$text, regex(term, ignore_case = TRUE))),
      paste0("count_", gsub("[^a-zA-Z]", "", terms_dutch))
    ),
    
    total_count = count_Lehman + count_economieischische + count_crisisesen)

# Germany

terms_german <- c(
  "Lehman",                     # Same term as in English
  "wirtschaft(lich|liche|licher|lichem|lichen)?",  # German terms for economy/economic (economy, economic)
  "krise(n)?"                   # German for crisis/crises
)

de = mutate(de,
            
            # Period - pre vs. post-Lehman
            Post = ifelse(date <= "2008-09-15", 0, 1),
            
            # Incumbent parties
            Gov = ifelse(party %in% c("CDU/CSU", "SPD"), 1, 0),
            
            # Sentiment analysis
            sentiment = get_sentiment(text, method = "nrc", lang = "german"),
            sentiment3 = sentiment/terms)

de <- de %>%
  mutate(
    !!!setNames(
      lapply(terms_german, function(term) str_count(.$text, regex(term, ignore_case = TRUE))),
      paste0("count_", gsub("[^a-zA-Z]", "", terms_german))
    ),
    
    total_count = count_Lehman + count_wirtschaftlichlichelicherlichemlichen + count_krisen)

# Spain

terms_spanish <- c(
  "Lehman",                     # Same term as in English
  "econom(ía|ico|ica|icos|icas)",        # Spanish terms for economy/economic (economy, economic)
  "crisis"                 # Spanish for crisis/crises
)

es = mutate(es,
            
            # Period - pre vs. post-Lehman
            Post = ifelse(date <= "2008-09-15", 0, 1),
            
            # Incumbent party
            Gov = ifelse(party %in% c("GPSOE"), 1, 0),
            
            # Sentiment analysis
            sentiment = get_sentiment(text, method = "nrc", lang = "spanish"),
            sentiment3 = sentiment/terms)

es <- es %>%
  mutate(
    !!!setNames(
      lapply(terms_spanish, function(term) str_count(.$text, regex(term, ignore_case = TRUE))),
      paste0("count_", gsub("[^a-zA-Z]", "", terms_spanish))
    ),
    
    total_count = count_Lehman + count_economaicoicaicosicas + count_crisis)

```

### Figure I.2

```{r warning=FALSE, message=FALSE, fig.width=20, fig.height=20}

# UK

p1 = uk %>%
  group_by(date) %>%
  dplyr::summarize(total = sum(total_count)) %>% 
  ggplot(aes(x = date, y = total)) +
  geom_point(size = 4, color = "red") + 
  geom_smooth(method = "loess", se = TRUE) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 400, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(uk$date), to = max(uk$date), by = 14), date_labels = "%d-%m") +
  scale_y_continuous(limits = c(0, 600)) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  +
  labs(y = "Count of the daily number of mentions\n(Lehman, economy, crisis)\nUK - House of Commons speeches", x = "January - December 2008", caption = "N = 63503 speeches\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "United Kingdom")

# NL

p2 = nl %>%
  group_by(date) %>%
  dplyr::summarize(total = sum(total_count)) %>% 
  ggplot(aes(x = date, y = total)) +
  geom_point(size = 4, color = "red") + 
  geom_smooth(method = "loess", se = TRUE) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 400, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(nl$date), to = max(nl$date), by = 14), date_labels = "%d-%m") +
  scale_y_continuous(limits = c(0, 600)) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  +
  labs(y = "Count of the daily number of mentions\n(Lehman, economy, crisis)\nNetherlands - Tweede Kammer speeches", x = "January - December 2008", caption = "N = 58135 speeches\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "Netherlands")

# Germany

p3 = de %>%
  group_by(date) %>%
  dplyr::summarize(total = sum(total_count)) %>% 
  ggplot(aes(x = date, y = total)) +
  geom_point(size = 4, color = "red") + 
  geom_smooth(method = "loess", se = TRUE) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 400, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(de$date), to = max(de$date), by = 14), date_labels = "%d-%m") +
  scale_y_continuous(limits = c(0, 600)) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  +
  labs(y = "Count of the daily number of mentions\n(Lehman, economy, crisis)\nGermany - Bundestag speeches", x = "January - December 2008", caption = "N = 13191 speeches\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "Germany")

# Spain

p4 = es %>%
  group_by(date) %>%
  dplyr::summarize(total = sum(total_count)) %>% 
  ggplot(aes(x = date, y = total)) +
  geom_point(size = 4, color = "red") + 
  geom_smooth(method = "loess", se = TRUE) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 400, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(es$date), to = max(es$date), by = 14), date_labels = "%d-%m") +
  scale_y_continuous(limits = c(0, 600)) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  +
  labs(y = "Count of the daily number of mentions\n(Lehman, economy, crisis)\nSpain - Congreso de los Disputados speeches", x = "January - December 2008", caption = "N = 7683 speeches\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "Spain") 

p1 + p2 + p3 + p4 + plot_layout(ncol = 2)

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigI2_ParlSpeech_mentions.pdf", dpi = 1200, width = 20, height = 20, unit = "in")

```

### Read the EUSpeech dataset

```{r}

# We employ data from the EUSpeech dataset (Schumacher et al. 2020) - https://osf.io/c79ha/files/osfstorage

load("Data/EUspeech_V2.RData")

df <- data.frame(
  text = as.character(corpus),  # Extract the text column
  docvars(corpus)        # Extract document-level variables
)

```

### Filter the EUSpeech dataset

```{r}

df = df %>%
  filter(format(date, "%Y") == "2008") %>%
  filter(country %in% c("Netherlands", "Great Britain", "Spain"))

uk_pm = df %>% filter(country %in% "Great Britain")
nl_pm = df %>% filter(country %in% "Netherlands")
es_pm = df %>% filter(country %in% "Spain")

```

### Recode the EUSpeech dataset

```{r}

# UK

terms <- c("Lehman", "econom(y|ic|ical)", "crisis(es)?") 

uk_pm = mutate(uk_pm,
            
            # Period - pre vs. post-Lehman
             Post = ifelse(date <= "2008-09-15", 0, 1))

uk_pm <- uk_pm %>%
  mutate(
    !!!setNames(
      lapply(terms, function(term) str_count(.$text, regex(term, ignore_case = TRUE))),
      paste0("count_", gsub("[^a-zA-Z]", "", terms))
    ),
    
    total_count = count_Lehman + count_economyicical + count_crisises)

# NL

terms_dutch <- c(
  "Lehman",                     # Same term as in English
  "econom(ie|isch|ische)",      # Dutch terms for economy/economic (economy, economical)
  "crisis(esen)?"               # Dutch for crisis/crises
)


nl_pm = mutate(nl_pm,
            
            
            # Period - pre vs. post-Lehman
             Post = ifelse(date <= "2008-09-15", 0, 1))

nl_pm <- nl_pm %>%
  mutate(
    !!!setNames(
      lapply(terms_dutch, function(term) str_count(.$text, regex(term, ignore_case = TRUE))),
      paste0("count_", gsub("[^a-zA-Z]", "", terms_dutch))
    ),
    
    total_count = count_Lehman + count_economieischische + count_crisisesen)

# Spain

terms_spanish <- c(
  "Lehman",                     # Same term as in English
  "econom(ía|ico|ica|icos|icas)",        # Spanish terms for economy/economic (economy, economic)
  "crisis"                 # Spanish for crisis/crises
)

es_pm = mutate(es_pm,

            # Period - pre vs. post-Lehman
             Post = ifelse(date <= "2008-09-15", 0, 1))

es_pm <- es_pm %>%
  mutate(
    !!!setNames(
      lapply(terms_spanish, function(term) str_count(.$text, regex(term, ignore_case = TRUE))),
      paste0("count_", gsub("[^a-zA-Z]", "", terms_spanish))
    ),
    
    total_count = count_Lehman + count_economaicoicaicosicas + count_crisis)

```

### Figure I.3

```{r  warning=FALSE, message=FALSE, fig.width=30, fig.height=10}

# UK

p1 = uk_pm %>%
  group_by(date) %>%
  dplyr::summarize(total = sum(total_count)) %>% 
  ggplot(aes(x = date, y = total)) +
  geom_point(size = 4, color = "red") + 
  geom_smooth(method = "loess", se = TRUE) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-08-01"), y = 73, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(uk_pm$date), to = max(uk_pm$date), by = 14), date_labels = "%d-%m") +
  #scale_y_continuous(limits = c(0, 110)) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  +
  labs(y = "Count of the daily number of mentions\n(Lehman, economy, crisis)\nUK - PM speeches", x = "January - December 2008", caption = "N = 82 speeches\nSource: The EUSpeech dataset (Schumacher et al. 2020)", title = "United Kingdom") 

# NL

p2 = nl_pm %>%
  group_by(date) %>%
  dplyr::summarize(total = sum(total_count)) %>% 
  ggplot(aes(x = date, y = total)) +
  geom_point(size = 4, color = "red") + 
  geom_smooth(method = "loess", se = TRUE) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 12, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(nl_pm$date), to = max(nl_pm$date), by = 14), date_labels = "%d-%m") +
  #scale_y_continuous(limits = c(0, 110)) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  +
  labs(y = "Count of the daily number of mentions\n(Lehman, economy, crisis)\nNetherlands - PM speeches", x = "January - December 2008", caption = "N = 50 speeches\nSource: The EUSpeech dataset (Schumacher et al. 2020)", title = "Netherlands")

# Spain

p3 = es_pm %>%
  group_by(date) %>%
  dplyr::summarize(total = sum(total_count)) %>% 
  ggplot(aes(x = date, y = total)) +
  geom_point(size = 4, color = "red") + 
  geom_smooth(method = "loess", se = TRUE) + 
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 40, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(es_pm$date), to = max(es_pm$date), by = 14), date_labels = "%d-%m") +
  #scale_y_continuous(limits = c(0, 110)) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none")  +
  labs(y = "Count of the daily number of mentions\n(Lehman, economy, crisis)\nSpain - PM speeches", x = "January - December 2008", caption = "N = 192 speeches\nSource: The EUSpeech dataset (Schumacher et al. 2020)", title = "Spain") 

p1 + p2 + p3 + plot_layout(ncol = 3)

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigI3_EUSpeech_PM_mentions.pdf", dpi = 1200, width = 30, height = 10, unit = "in")

```

### Table I.1

```{r results='asis'}

tabi1 = list()

tabi1[[1]] = lm(data = dplyr::filter(ess, IncumbentPM_vote == 0), weights = Weights, Gov_sat ~ Post + factor(cntry))

tabi1[[2]] = lm(data = dplyr::filter(ess, cntry == "CH" & IncumbentPM_vote == 0), weights = Weights, Gov_sat ~ Post)

tabi1[[3]] = lm(data = dplyr::filter(ess, cntry == "DE" & IncumbentPM_vote == 0), weights = Weights, Gov_sat ~ Post)

tabi1[[4]] = lm(data = dplyr::filter(ess, cntry == "ES" & IncumbentPM_vote == 0), weights = Weights, Gov_sat ~ Post)

tabi1[[5]] = lm(data = dplyr::filter(ess, cntry == "GB" & IncumbentPM_vote == 0), weights = Weights, Gov_sat ~ Post)

tabi1[[6]] = lm(data = dplyr::filter(ess, cntry == "NL" & IncumbentPM_vote == 0), weights = Weights, Gov_sat ~ Post)

tabi1[[7]] = lm(data = dplyr::filter(ess, cntry == "NO" & IncumbentPM_vote == 0), weights = Weights, Gov_sat ~ Post)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabi1, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("All","CH", "DE", "ES", "UK", "NL", "NO"), omit.coef = "cntry|Sex|Age|Education_highest|Residence|Marital_status|Income_subjective|Ethnic_minority|Country_citizen|Paidwork_7days|Unempl_7days|Educ_7days|Retired_7days|Disabled_sick_7days|Housework_7days|Turnout_yes|IncumbentPM_vote", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: satisfaction with the national government (0-10). All models use survey weights.", caption = "Satisfaction with the national government (full and country-level results, past incumbent PM voters excluded)")
#cat('</div>')

```

### Figure I.4

```{r warning=FALSE, message=FALSE, fig.width=20, fig.height=20}

# UK

p5 = uk %>%
  group_by(date, Gov) %>%
  dplyr::summarize(mean_sentiment = mean(sentiment3)) %>% 
  ggplot(aes(x = date, y = mean_sentiment)) +
  geom_point(aes(colour = as.factor(Gov)), size = 4) +
  geom_hline(yintercept = 0, linetype = "dotdash", color = "black") +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 0.01, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(uk$date), to = max(uk$date), by = 14), date_labels = "%d-%m") +
    scale_color_manual(
    name = "Government party?",  # Legend title
    values = c("0" = "red", "1" = "blue"),  # Adjust colors as needed
    labels = c("0" = "No", "1" = "Yes")  # Legend labels
  ) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "top")  +
  labs(y = "Daily mean sentiment by government participation\nUK - House of Commons speeches", x = "January - December 2008", caption = "N = 63503 speeches\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "United Kingdom")

# NL

p6 = nl %>%
  group_by(date, Gov) %>%
  dplyr::summarize(mean_sentiment = mean(sentiment3)) %>% 
  ggplot(aes(x = date, y = mean_sentiment)) +
  geom_point(aes(colour = as.factor(Gov)), size = 4) +
  geom_hline(yintercept = 0, linetype = "dotdash", color = "black") +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 0.01, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(nl$date), to = max(nl$date), by = 14), date_labels = "%d-%m") +
    scale_color_manual(
    name = "Government coalition?",  # Legend title
    values = c("0" = "red", "1" = "blue"),  # Adjust colors as needed
    labels = c("0" = "No", "1" = "Yes")  # Legend labels
  ) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "top")  +
  labs(y = "Daily mean sentiment by government participation\nNetherlands - Tweede Kammer speeches", x = "January - December 2008", caption = "N = 58135 speeches\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "Netherlands")

# Germany

p7 = de %>%
  group_by(date, Gov) %>%
  dplyr::summarize(mean_sentiment = mean(sentiment3)) %>% 
  ggplot(aes(x = date, y = mean_sentiment)) +
  geom_point(aes(colour = as.factor(Gov)), size = 4) +
  geom_hline(yintercept = 0, linetype = "dotdash", color = "black") +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 0.02, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(de$date), to = max(de$date), by = 14), date_labels = "%d-%m") +
    scale_color_manual(
    name = "Government coalition?",  # Legend title
    values = c("0" = "red", "1" = "blue"),  # Adjust colors as needed
    labels = c("0" = "No", "1" = "Yes")  # Legend labels
  ) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "top")  +
  labs(y = "Daily mean sentiment by government participation\nGermany - Bundestag speeches", x = "January - December 2008", caption = "N = 13191 speeches\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "Germany") 

# Spain

p8 = es %>%
  group_by(date, Gov) %>%
  dplyr::summarize(mean_sentiment = mean(sentiment3)) %>% 
  ggplot(aes(x = date, y = mean_sentiment)) +
  geom_point(aes(colour = as.factor(Gov)), size = 4) +
  geom_hline(yintercept = 0, linetype = "dotdash", color = "black") +
  geom_vline(xintercept = as.Date("2008-09-15"), linetype = "dotdash", color = "black") +
  annotate("text", x = as.Date("2008-07-15"), y = 0.3, label = "15 September\nLehman Brothers\ncrash", colour="black", size = 7) +
  scale_x_date(breaks = seq(from = min(es$date), to = max(es$date), by = 14), date_labels = "%d-%m") +
    scale_color_manual(
    name = "Government party?",  # Legend title
    values = c("0" = "red", "1" = "blue"),  # Adjust colors as needed
    labels = c("0" = "No", "1" = "Yes")  # Legend labels
  ) +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=14, angle = 60, vjust = 1, hjust = 1),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "top")  +
  labs(y = "Daily mean sentiment by government participation\nSpain - Congreso de los Disputados speeches", x = "January - December 2008", caption = "N = 7683 speeches.\nSource: The ParlSpeech dataset (Rauh and Schwalbach 2020)", title = "Spain")

p5 + p6 + p7 + p8 + plot_layout(ncol = 2)

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigI4_ParlSpeech_sentiment_all_govstatus.pdf", dpi = 1200, width = 20, height = 20, unit = "in")

```

## Appendix J

### Read and filter the KOF Globalization Index data

```{r}

# We employ data from the KOF Globalization Index (Gygli et al. 2019) - https://kof.ethz.ch/en/forecasts-and-indicators/indicators/kof-globalisation-index.html

kof <- read_excel("Data/KOFGI_2024_public.xlsx") 

kof = kof %>%
  filter(year %in% "2007") %>%
  filter(country %in% c("World", "High income", "Europe and Central Asia", "Netherlands", "Norway", "North America", "Spain", "Germany", "United Kingdom", "Switzerland"))

```

### Figure J.1

```{r warning=FALSE, fig.width=20, fig.height=17.5}

kof %>%
  select(country, KOFGI, KOFEcGI, KOFTrGI, KOFFiGI, KOFInGI) %>%
  pivot_longer(-country, names_to = "Variable", values_to = "Value") %>%
  mutate(Variable = factor(Variable, levels = c("KOFGI", "KOFEcGI", "KOFTrGI", "KOFFiGI", "KOFInGI")),    
         country = factor(country, levels = c("World", "High income", "North America", "Europe and Central Asia", "United Kingdom","Netherlands", "Norway", "Spain", "Germany", "Switzerland")), 
         Variable = fct_recode(Variable,
                               "KOF Globalisation\nIndex" = "KOFGI",
                               "Economic\nGlobalization" = "KOFEcGI",
                               "Trade\nGlobalization" = "KOFTrGI",
                               "Financial\nGlobalization" = "KOFFiGI",
                               "Informational\nGlobalization" = "KOFInGI")) %>%
  ggplot(aes(x = country, y = Value, fill = Variable)) +
  geom_col(position = "dodge") +
    geom_text(aes(label = round(Value, 1)), 
            position = position_dodge(width = 0.9),
            vjust = -0.2, size = 7) +
  facet_wrap(~Variable) +
  labs(x = "", y = "Index Value (0-100), 2007", fill = "Index Type", caption = "Source: Gygli et al. 2019") +
  theme2 +
  theme_bw() +
  theme(plot.title = element_text(size = 30, hjust = 0.5, face="bold"),
        axis.title.y = element_text(size = 28),
        axis.title.x = element_text(size = 28),
        strip.text.x = element_text(size = 28, face="bold"),
        strip.text.y = element_text(size = 28, face="bold"),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=20, angle = 90, vjust = 0.5),
        axis.text.y = element_text(size=20),
        legend.title = element_text(size = 20),
        legend.text = element_text(size = 16)) +
  theme(legend.position = "none") +
  scale_fill_manual(values = rep("blue", 5))
  
# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigJ1_KOF.pdf", dpi = 1200, width = 20, height = 17.5, unit = "in")

```

## Appendix K

### Read Flash Eurobarometer 251 data

```{r}
 
# We employ data from Flash Eurobarometer 251 - https://search.gesis.org/research_data/ZA4982

data = read_dta("Data/Lehman_Euro.dta")

```

### Recode Flash Eurobarometer 251 data

```{r}

data = mutate(data,
              
              # Date of the interview
              Date = dmy(trim(paste(as.character(day), "-", as.character(month), "-" , as.character(year)))),
              minute = ifelse(minute == 60, 0, minute),
              hour = ifelse(minute == 60, hour + 1, hour),
              Time = hm(trim(paste(as.character(hour), ":", as.character(minute)))),

              Datetime = dmy_hm(paste(trim(paste(as.character(day), "-", as.character(month), "-", as.character(year), " " , as.character(hour), ":", as.character(minute))))),
              
              # Period - pre vs. post-Lehman
              Post = ifelse(Date <= "2008-09-15", 0, 1),
              
              # Country
              Country = factor(case_when(
                  country  %in% 1 ~ "France",
                  country  %in% 2 ~ "Belgium",
                  country  %in% 3 ~ "The\nNetherlands",
                  country  %in% 4 ~ "Germany",
                  country  %in% 5 ~ "Italy",
                  country  %in% 6 ~ "Luxembourg",
                  country  %in% 8 ~ "Ireland",
                  country  %in% 11 ~ "Greece",
                  country  %in% 12 ~ "Spain",
                  country  %in% 13 ~ "Portugal",
                  country  %in% 16 ~ "Finland",
                  country  %in% 18 ~ "Austria",
                  country  %in% 19 ~ "Cyprus",
                  country  %in% 25 ~ "Malta",
                  country  %in% 28 ~ "Slovenia",
                   TRUE ~ NA_character_)),
              
              # Positive evaluation of the EU membership
              EU_membership_good = case_when(
                c1  %in% 1 ~ 1,
                c1  %in% c(2, 3) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Inflation rate expectation - higher inflation in 2008 compared to 2007
              Inflation_expect_higher = case_when(
                q15b  %in% 1 ~ 1,
                q15b  %in% c(2, 3) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Expectation of household income decrease compared to the previous year
              Householdincome_expect_decrease = case_when(
                q16b  %in% 2 ~ 1,
                q16b  %in% c(1, 3) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Female
              Female = ifelse(d1 %in% 2, 1, 0),
              
              # Age
              Age = case_when(
                d2 %in% 0 ~ as.double(NA),
                TRUE ~ as.numeric(d2)),
              Age_under40 = ifelse(Age <=40, 1, 0),
              
              # Education
              Still_in_education = case_when(
                d3  %in% 0 ~ 1,
                d3  %nin% c(0, 99) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Employee
              Employee = case_when(
                d4  %in% c(21:27) ~ 1,
                d4  %in% c(11:15, 31:34, 41:45) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Residence
              Big_city = case_when(
                d6  %in% 1 ~ 1,
                d6  %in% c(2, 3) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Weights
              Weights = w4,
              
              # ID
              ID = uniquid)

```

### Figure K.1

```{r warning=FALSE, fig.width=12.5, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 1:4) {
  # Define the start and end dates for the current window
  start_date <- target_date
  end_date <- target_date + i
  
  # Filter the dataset based on the current window
  window_data <- data %>%
    filter(Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(EU_membership_good ~ Post + Female + Age_under40 + Still_in_education + Employee + Big_city + factor(Country), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_after = No_days - 1)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(1,4,1), limits = c(1,4)) +
  scale_y_continuous(breaks = seq(-0.05,0.05,0.01), limits = c(-0.05,0.05)) +
  labs(x = "Number of days after the Lehman Brothers announcement", y = "Positive evaluation of the EU membership\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigK1_Euro_EU_all_controls.pdf", dpi = 1200, width = 12.5, height = 10, unit = "in")

```

### Figure K.2

```{r warning=FALSE, fig.width=12.5, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 1:4) {
  # Define the start and end dates for the current window
  start_date <- target_date
  end_date <- target_date + i
  
  # Filter the dataset based on the current window
  window_data <- data %>%
    filter(Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Inflation_expect_higher ~ Post + Female + Age_under40 + Still_in_education + Employee + Big_city + factor(Country), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_after = No_days - 1)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(1,4,1), limits = c(1,4)) +
  scale_y_continuous(breaks = seq(-0.05,0.05,0.01), limits = c(-0.05,0.05)) +
  labs(x = "Number of days after the Lehman Brothers announcement", y = "Higher inflation in 2008 compared to 2007\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigK2_Euro_Inflationexpect_all_controls.pdf", dpi = 1200, width = 12.5, height = 10, unit = "in")

```

### Figure K.3

```{r warning=FALSE, fig.width=12.5, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 1:4) {
  # Define the start and end dates for the current window
  start_date <- target_date
  end_date <- target_date + i
  
  # Filter the dataset based on the current window
  window_data <- data %>%
    filter(Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Householdincome_expect_decrease ~ Post + Female + Age_under40 + Still_in_education + Employee + Big_city + factor(Country), data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_after = No_days - 1)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(1,4,1), limits = c(1,4)) +
  scale_y_continuous(breaks = seq(-0.05,0.05,0.01), limits = c(-0.05,0.05)) +
  labs(x = "Number of days after the Lehman Brothers announcement", y = "Expectation of household income decrease\ncompared to the previous year\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigK3_Euro_Householdexpect_all_controls.pdf", dpi = 1200, width = 12.5, height = 10, unit = "in")

```

## Appendix L

### Read Standard Eurobarometer 69 and Standard Eurobarometer 70 data

```{r}

# We employ data from Standard Eurobarometer 69 and Standard Eurobarometer 70 - https://search.gesis.org/research_data/ZA4744 and https://search.gesis.org/research_data/ZA4819

pre = read_dta("Data/ZA4744.dta") %>% filter(v7 %nin% c("TR", "HR", "CY-TCC", "MK"))

post = read_dta("Data/ZA4819.dta") %>% filter(v7 %nin% c("TR", "HR", "CY-TCC", "MK"))

```

### Recode Standard Eurobarometer 69 and Standard Eurobarometer 70 data

```{r}

# Pre-Lehman

pre = mutate(pre,
             
             # Post
             Post = 0,
             
             # Expectations (next 12 months) - national economic situation
             Expect_natec_worse = case_when(
               v90 %in% 2 ~ 1,
               v90 %in% c(1, 3) ~ 0,
               TRUE ~ as.double(NA)),
             
             # National government trust
             Gov_trust = case_when(
             v213 %in% 1 ~ 1,
             v213 %in% 2 ~ 0,
             TRUE ~ as.double(NA)),
             
             # Ideology
             Ideology = v761,
             
             # Marital status
             Married = case_when(
               v764 %in% 1 ~ 1,
               v764 %in% c(2:9) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Education
             Education = v766,
             
             # Gender
             Female = ifelse(v767 %in% 2, 1, 0),
             
             # Age
             Age = v768,
             
             # Rural vs. urban
             Rural = case_when(
               v773 %in% 1 ~ 1,
               v773 %in% c(2:3) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Occupation
             Retired = case_when(
               v771 %in% 4 ~ 1,
               v771 %in% c(1:3, 5:18) ~ 0,
               TRUE ~ as.double(NA)),

             # Weights - EU27
             Weights = v40,
             
             # Country
             Country = v7,
             
             Country2 = factor(case_when(
             v7 %in% c("GB-NIR", "GB-GBN") ~ "GB",
             v7 %in% c("DE-W", "DE-E") ~ "DE",
             TRUE ~ v7)))

# Post-Lehman

post = mutate(post,
             
             # Post
             Post = 1,
             
             # Expectations (next 12 months) - national economic situation
             Expect_natec_worse = case_when(
               v124 %in% 2 ~ 1,
               v124 %in% c(1, 3) ~ 0,
               TRUE ~ as.double(NA)),
             
             # National government trust
             Gov_trust = case_when(
             v228 %in% 1 ~ 1,
             v228 %in% 2 ~ 0,
             TRUE ~ as.double(NA)),
             
             # Ideology
             Ideology = v664,
             
             # Marital status
             Married = case_when(
               v667 %in% 1 ~ 1,
               v667 %in% c(2:9) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Education
             Education = v669,
             
             # Gender
             Female = ifelse(v670 %in% 2, 1, 0),
             
             # Age
             Age = v671,
             
             # Rural vs. urban
             Rural = case_when(
               v674 %in% 1 ~ 1,
               v674 %in% c(2:3) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Occupation
             Retired = case_when(
               v477 %in% 4 ~ 1,
               v477 %in% c(1:3, 5:18) ~ 0,
               TRUE ~ as.double(NA)),
             
             # Weights - EU27
             Weights = v40,
             
             # Country
             Country = v7,
             
             Country2 = factor(case_when(
             v7 %in% c("GB-NIR", "GB-GBN") ~ "GB",
             v7 %in% c("DE-W", "DE-E") ~ "DE",
             TRUE ~ v7)))

```

### Merge Standard Eurobarometer 69 and Standard Eurobarometer 70 data

```{r}

data1 = pre %>% select(Post, Gov_trust, Expect_natec_worse, Weights, Country, Country2, Ideology, Married, Education, Female, Age, Rural, Retired)
data2 = post %>% select(Post, Gov_trust, Expect_natec_worse, Weights, Country, Country2, Ideology, Married, Education, Female, Age, Rural, Retired)

data_df <- do.call("rbind", list(data1, data2))

```

### Table L.1

```{r results='asis'}

tabl1 = list()

tabl1[[1]] = lm(data = data_df, weights = Weights, Expect_natec_worse ~ Post + factor(Country2))

tabl1[[2]] = lm(data = data_df, weights = Weights, Expect_natec_worse ~ Post + factor(Country2) + Female + Age + Rural + Retired + Education + Married + Ideology)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabl1, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Country2|Female|Age|Rural|Retired|Education|Married|Ideology", custom.coef.names = c("Intercept", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS regressions with standard errors in parentheses. Dependent variable for both models: expectation for the next twelve months - the national economic situation will be worse (binary). Both models include country fixed effects and survey weights. Model 2 controls for sex, age, type of community, occupation, education, marital status, and ideology.", caption = "Expectation for the next twelve months - the national economic situation will be worse (all countries, EU27 - 2008)")
#cat('</div>')

```

### Table L.2

```{r results='asis'}

tabll2 = list()

tabll2[[1]] = lm(data = data_df, weights = Weights, Gov_trust ~ Post + factor(Country2))

tabll2[[2]] = lm(data = data_df, weights = Weights, Gov_trust ~ Post + factor(Country2) + Female + Age + Rural + Retired + Education + Married + Ideology)

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabll2, stars = c(0.01, 0.05, 0.1), digits = 3, omit.coef = "Country2|Female|Age|Rural|Retired|Education|Married|Ideology", custom.coef.names = c("Intercept", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS regressions with standard errors in parentheses. Dependent variable for both models: trust in the national government (binary). Both models include country fixed effects and survey weights. Model 2 controls for sex, age, type of community, occupation, education, marital status, and ideology.", caption = "Trust in the national government (all countries, EU27 - 2008)")
#cat('</div>')

```

## Appendix M

### Read the ANES datataset

```{r}

# We employ data from ANES 2008 - https://electionstudies.org/data-center/2008-time-series-study/

anes = read_dta("Data/anes_2008.dta")

```

### Recode the ANES datataset

```{r}

anes = mutate(anes,
              
              # ID
              ID = V080001,
              
              # Date
              Date = dmy(trim(paste(V082001b, "-", V082001a, "-" , "2008"))),
              
              # Period - pre vs. post-Lehman
              Post = ifelse(Date <= "2008-09-15", 0, 1),
              
              # Sociotropic economic retrospective evaluations
              Soc_ret_ec_worse = case_when(
                V083083 %in% 5 ~ 1,  
                V083083 %in% c(1, 3) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Egotropic economic retrospective evaluations
              Ego_ret_ec_worse = case_when(
                V083057 %in% 3 ~ 1,  
                V083057 %in% c(1, 5) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Job approval - President Bush
              President_approval_job = case_when(
                V083028 %in% 1 ~ 1,  
                V083028 %in% 5 ~ 0,
                TRUE ~ as.double(NA)),
              
              # Vote intention - Obama 2008
              Vote_intention_Obama = case_when(
                V083169a %in% 1 ~ 1,  
                V083169a %in% c(2, 5, 7) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Campaign interest
              Campaign_interest_1 = case_when(
                V083001a %in% 1 ~ 1,
                V083001a %in% c(3, 5) ~ 0,
                TRUE ~ as.double(NA)),
              
              Campaign_interest_2 = case_when(
                V083001b %in% 1:2 ~ 1,
                V083001b %in% 3:5 ~ 0,
                TRUE ~ as.double(NA)),
              
              Campaign_interest = coalesce(Campaign_interest_1, Campaign_interest_2),
              
              # Politics - complicated
              Complicated_1 = case_when(
                V083079a %in% 1:2 ~ 1,  
                V083079a %in% 3:5 ~ 0,
                TRUE ~ as.double(NA)),
              
              Complicated_2 = case_when(
                V083080a %in% 1:2 ~ 1,  
                V083080a %in% 3:5 ~ 0,
                TRUE ~ as.double(NA)),
              
              Complicated = coalesce(Complicated_1, Complicated_2),
              
              # Partisanship
              PartyID_Democrat = case_when(
                V083097 %in% 1 ~ 1,  
                V083097 %in% 2:5 ~ 0,
                TRUE ~ as.double(NA)),
              
              # Voted in 2004
              Turnout_2004 = case_when(
                V083007 %in% 1 ~ 1,  
                V083007 %in% 5 ~ 0,
                TRUE ~ as.double(NA)),
              
              # Voted Kerry in 2004
              Kerry_2004 = case_when(
                V083007a %in% 1 ~ 1,  
                V083007a %in% c(-1, 3, 7) ~ 0,
                TRUE ~ as.double(NA)),
              
              # Controls
              Male = ifelse(V081101 == 1, 1, 0),
              
              White = case_when(
                V081102 %in% 1 ~ 1,  
                V081102 %in% c(2:7) ~ 0,
                TRUE ~ as.double(NA)),
              
              Latino = case_when(
                V081103 %in% 1 ~ 1,  
                V081103 %in% 2 ~ 0,
                TRUE ~ as.double(NA)),
              
              Age = ifelse(V081104 %in% c(-9, -8), as.double(NA), as.numeric(V081104)),
              
              Children_household_yes = case_when(
                V081109 %in% c(1:7) ~ 1,  
                V081109 %in% 0 ~ 0,
                TRUE ~ as.double(NA)),
              
              South = ifelse(V081204 == 3, 1, 0),
              
              Urban = case_when(
                V082025 %in% c(4) ~ 1,  
                V082025 %in% c(1:3, 5:7) ~ 0,
                TRUE ~ as.double(NA)),
              
              Religious_serv = case_when(
                V083183 %in% c(-9, -8) ~ as.double(NA),
                TRUE ~ as.numeric(V083183)),
              
              Married_1 = case_when(
                V083216a %in% 1 ~ 1,  
                V083216a %in% 2:6 ~ 0,
                TRUE ~ as.double(NA)),
              
              Married_2 = case_when(
                V083216b %in% 1 ~ 1,  
                V083216b %in% 2:6 ~ 0,
                TRUE ~ as.double(NA)),
              
              Married = coalesce(Married_1, Married_2),
              
              Years_education = case_when(
                V083217 %in% c(-9, -8) ~ as.double(NA),
                TRUE ~ as.numeric(V083217)),
              
              Empl_status = case_when(
                V083222 %in% c(-9, -8) ~ as.double(NA),
                TRUE ~ as.numeric(V083222)),
              
              Income_pers = case_when(
                V083249 %in% c(-9, -8) ~ as.double(NA),
                TRUE ~ as.numeric(V083249)),
              
              Middle_class = case_when(
                V083250a %in% 1 ~ 1,  
                V083250a %in% c(-1, 0, 5:7) ~ 0,
                TRUE ~ as.double(NA)),
              
              Parents_USborn = case_when(
                V083257 %in% 1 ~ 1,  
                V083257 %in% c(2:3) ~ 0,
                TRUE ~ as.double(NA)),
              
              Internet_access = case_when(
                V083018 %in% 1 ~ 1,  
                V083018 %in% 5 ~ 0,
                TRUE ~ as.double(NA)),
              
              Owns_home = case_when(
                V083281 %in% 1 ~ 1,  
                V083281 %in% c(5, 7) ~ 0,
                TRUE ~ as.double(NA)),
              
              Stocks_yes = case_when(
                V083059 %in% 1 ~ 1,  
                V083059 %in% 5 ~ 0,
                TRUE ~ as.double(NA)),
              
              Health_insurance = case_when(
                V083060 %in% 1 ~ 1,  
                V083060 %in% 5 ~ 0,
                TRUE ~ as.double(NA)),
              
              Union_member_yes = case_when(
                V083246 %in% 1 ~ 1,  
                V083246 %in% 5 ~ 0,
                TRUE ~ as.double(NA)),
              
              # Weights
              Weights = V080101)

```

### Table M.1

```{r}

descriptives <- c("Soc_ret_ec_worse", "Ego_ret_ec_worse", "President_approval_job", "Vote_intention_Obama", "Campaign_interest", "Complicated", "Post", "PartyID_Democrat", "Male", "White", "Latino", "Age", "Children_household_yes", "South", "Urban", "Religious_serv", "Married", "Years_education", "Empl_status", "Income_pers", "Middle_class", "Parents_USborn")

data_sub <- dplyr::select(anes, descriptives)

psych::describe(data_sub, skew = TRUE, check = TRUE) %>%
  as.data.frame() %>%
  dplyr::select(n, mean, sd, median, min, max, se) %>%
  round(2) # %>% xtable()

```

### Figure M.1

```{r warning=FALSE, message=FALSE, fig.width=13, fig.height=7.5}

anes2 = anes %>%
    select("PartyID_Democrat", "Male", "White", "Latino", "Age", "Children_household_yes", "South", "Urban", "Turnout_2004", "Kerry_2004", "Internet_access", "Owns_home", "Stocks_yes", "Health_insurance", "Religious_serv", "Married", "Years_education", "Empl_status", "Union_member_yes", "Income_pers", "Middle_class", "Parents_USborn", "Post") %>%
  as.data.frame()
anes2[,1:23] <- sapply(anes2[,1:23],as.numeric)

# For the balance checks, we employ the code from Hartman and Hidalgo (2018)

replicate_strict = as.data.frame(run_equiv(X = subset(anes2, select = c("PartyID_Democrat", "Male", "White", "Latino", "Age", "Children_household_yes", "South", "Urban", "Turnout_2004", "Kerry_2004", "Internet_access", "Owns_home", "Stocks_yes", "Health_insurance", "Religious_serv", "Married", "Years_education", "Empl_status", "Union_member_yes", "Income_pers", "Middle_class", "Parents_USborn")), 
                                           Tr = anes2$Post, epsilon.method = "custom", custom.epsilon = 0.36,
                                           fdr_correct = TRUE))

g1 <- generate_plot(replicate_strict, panel.widths = c(2.5, 1.25, 5, 1.2, 1.2), 
              display.names = c("Democrat", "Male", "White", "Latino", "Age", "Children in the household", "Southern region", "Urban residence", "Voted in 2004", "Voted Kerry in 2004", "Internet access", "Owns their home", "Owns stocks", "Has health insurance", "Attends religious service", "Married", "Years of education", "Employment status", "Labor union member", "Personal income", "Middle class", "Both parents US-born"), 
              pval.rounding = 3, fdr_correct = TRUE)

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigM1_ANES_Balance.png", g1, dpi = 600, width = 13, height = 7.5, unit = "in")

```

### Table M.2

```{r results='asis'}

tabm2 = list()

tabm2[[1]] = lm(data = anes, weights = Weights, Soc_ret_ec_worse ~ Post)

tabm2[[2]] = lm(data = anes, weights = Weights, Soc_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm2[[3]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Soc_ret_ec_worse ~ Post)

tabm2[[4]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Soc_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm2[[5]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Soc_ret_ec_worse ~ Post)

tabm2[[6]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Soc_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm2[[7]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Soc_ret_ec_worse ~ Post)

tabm2[[8]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Soc_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm2[[9]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Soc_ret_ec_worse ~ Post)

tabm2[[10]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Soc_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

# Our ANES date selection follows the approach used for the ESS, but note that ANES data collection began on 2 September 2008.

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabm2, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "PartyID_Democrat|Male|White|Latino|Age|Children_household_yes|South|Urban|Religious_serv|Married|Years_education|Empl_status|Income_pers|Middle_class|Parents_USborn", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: sociotropic retrospective economic evaluations - worse compared to the last 12 months (binary). All models use survey weights.", caption = "Sociotropic retrospective economic evaluations (US) - worse compared to the last 12 months")
#cat('</div>')

```

### Figure M.2

```{r warning=FALSE, fig.width=15, fig.height=10.5}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- anes %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Soc_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.1,0.3,0.1), limits = c(-0.1,0.3)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Sociotropic retrospective economic evaluations (worse)\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigM2_ANES_Sociotropic_incremental_controls.pdf", dpi = 1200, width = 15, height = 10.5, unit = "in")

```

### Table M.3

```{r results='asis'}

tabm3 = list()

tabm3[[1]] = lm(data = anes, weights = Weights, Ego_ret_ec_worse ~ Post)

tabm3[[2]] = lm(data = anes, weights = Weights, Ego_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm3[[3]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Ego_ret_ec_worse ~ Post)

tabm3[[4]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Ego_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm3[[5]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Ego_ret_ec_worse ~ Post)

tabm3[[6]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Ego_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm3[[7]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Ego_ret_ec_worse ~ Post)

tabm3[[8]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Ego_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm3[[9]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Ego_ret_ec_worse ~ Post)

tabm3[[10]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Ego_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

# Our ANES date selection follows the approach used for the ESS, but note that ANES data collection began on 2 September 2008.

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabm3, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "PartyID_Democrat|Male|White|Latino|Age|Children_household_yes|South|Urban|Religious_serv|Married|Years_education|Empl_status|Income_pers|Middle_class|Parents_USborn", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: egotropic retrospective economic evaluations - worse compared to the last 12 months (binary). All models use survey weights.", caption = "Egotropic retrospective economic evaluations (US) - worse compared to the last 12 months")
#cat('</div>')

```

### Figure M.3

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- anes %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Ego_ret_ec_worse ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  #scale_y_continuous(breaks = seq(-0.5,0.5,0.1), limits = c(-0.5,0.5)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Egotropic retrospective economic evaluations (worse)\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigM3_ANES_Egotropic_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Table M.4

```{r results='asis'}

tabm4 = list()

tabm4[[1]] = lm(data = anes, weights = Weights, President_approval_job ~ Post)

tabm4[[2]] = lm(data = anes, weights = Weights, President_approval_job ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm4[[3]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, President_approval_job ~ Post)

tabm4[[4]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, President_approval_job ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm4[[5]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, President_approval_job ~ Post)

tabm4[[6]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, President_approval_job ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm4[[7]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, President_approval_job ~ Post)

tabm4[[8]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, President_approval_job ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm4[[9]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, President_approval_job ~ Post)

tabm4[[10]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, President_approval_job ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

# Our ANES date selection follows the approach used for the ESS, but note that ANES data collection began on 2 September 2008.

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabm4, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "PartyID_Democrat|Male|White|Latino|Age|Children_household_yes|South|Urban|Religious_serv|Married|Years_education|Empl_status|Income_pers|Middle_class|Parents_USborn", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: presidential job approval (binary). All models use survey weights.", caption = "Presidential job approval (US)")
#cat('</div>')

```

### Figure M.4

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- anes %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(President_approval_job ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.2,0.3,0.1), limits = c(-0.2,0.3)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Presidential job approval\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigM4_ANES_Jobapproval_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

### Table M.5

```{r results='asis'}

tabm5 = list()

tabm5[[1]] = lm(data = anes, weights = Weights, Vote_intention_Obama ~ Post)

tabm5[[2]] = lm(data = anes, weights = Weights, Vote_intention_Obama ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm5[[3]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Vote_intention_Obama ~ Post)

tabm5[[4]] = lm(data = dplyr::filter(anes, (Date > "2008-09-09") & (Date < "2008-09-21")), weights = Weights, Vote_intention_Obama ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm5[[5]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Vote_intention_Obama ~ Post)

tabm5[[6]] = lm(data = dplyr::filter(anes, (Date > "2008-09-04") & (Date < "2008-09-26")), weights = Weights, Vote_intention_Obama ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm5[[7]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Vote_intention_Obama ~ Post)

tabm5[[8]] = lm(data = dplyr::filter(anes, (Date > "2008-08-31") & (Date < "2008-10-01")), weights = Weights, Vote_intention_Obama ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

tabm5[[9]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Vote_intention_Obama ~ Post)

tabm5[[10]] = lm(data = dplyr::filter(anes, (Date > "2008-08-21") & (Date < "2008-10-16")), weights = Weights, Vote_intention_Obama ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn)

# Our ANES date selection follows the approach used for the ESS, but note that ANES data collection began on 2 September 2008.

#cat('<div style="font-size: 80%;">') # use htmlreg for knitting
screenreg(tabm5, stars = c(0.01, 0.05, 0.1), digits = 3, custom.model.names = c("Full sample", "Full sample", "5 days", "5 days", "10 days", "10 days", "15 days", "15 days", "30 days", "30 days"), omit.coef = "PartyID_Democrat|Male|White|Latino|Age|Children_household_yes|South|Urban|Religious_serv|Married|Years_education|Empl_status|Income_pers|Middle_class|Parents_USborn", custom.coef.names = c("(Intercept)", "Post-Lehman interview"), reorder.coef = c(2, 1), custom.note = "Note: %stars. OLS estimations with standard errors in parentheses. Dependent variable for all models: vote intention for Obama (binary). All models use survey weights.", caption = "Vote intention for Obama (US)")
#cat('</div>')

```

### Figure M.5

```{r warning=FALSE, fig.width=15, fig.height=10}

# Define the target date
target_date <- as.Date("2008-09-15")

# Create an empty list to store the regression coefficients and confidence intervals
coefficient_list <- list()
confidence_interval_list_90 <- list()
confidence_interval_list_95 <- list()

# Loop over the incremental time windows
for (i in 0:60) {
  # Define the start and end dates for the current window
  start_date <- target_date - i
  end_date <- target_date + i + 1
  
  # Filter the dataset based on the current window
  window_data <- anes %>%
    filter(Date >= start_date, Date <= end_date)
  
  # Check if the window has enough observations
  if (nrow(window_data) >= 10) {  # Minimum number of observations required for regression
    # Estimate the regression model
    model <- lm(Vote_intention_Obama ~ Post + PartyID_Democrat + Male + White + Latino + Age + Children_household_yes + South + Urban + Religious_serv + Married + Years_education + Empl_status + Income_pers + Middle_class + Parents_USborn, data = window_data, weights = Weights)
    
    # Store the coefficients and confidence intervals
    coefficient_list[[paste(as.character(start_date), as.character(end_date))]] <- coef(model)["Post"]
    confidence_interval_list_90[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.9)["Post", , drop = FALSE][1, ]
    confidence_interval_list_95[[paste(as.character(start_date), as.character(end_date))]] <- confint(model, level = 0.95)["Post", , drop = FALSE][1, ]
  }
}

# Convert the coefficient lists into data frames
coefficients_df <- data.frame(Date = names(coefficient_list),
                             Coefficient = unlist(coefficient_list),
                             CI_90_lower = unlist(lapply(confidence_interval_list_90, "[", 1)),
                             CI_90_upper = unlist(lapply(confidence_interval_list_90, "[", 2)),
                             CI_95_lower = unlist(lapply(confidence_interval_list_95, "[", 1)),
                             CI_95_upper = unlist(lapply(confidence_interval_list_95, "[", 2))) %>%
                             mutate(Date_start = as.Date(substr(Date,1,10)),
                                    Date_end = as.Date(str_sub(Date,start = -10)),
                                    No_days = Date_end - Date_start + 1,
                                    Days_before_after = No_days/2)

# Plot the coefficients with confidence intervals
ggplot(coefficients_df, aes(x = Days_before_after, y = Coefficient)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red4", size = 1) +
  geom_errorbar(aes(ymin = CI_95_lower, ymax = CI_95_upper), width = 0, color = "grey70", size = 1) +
  geom_errorbar(aes(ymin = CI_90_lower, ymax = CI_90_upper), width = 0, color = "black", size = 1) +
  scale_x_continuous(breaks = seq(0,60,5), limits = c(0,60)) +
  scale_y_continuous(breaks = seq(-0.2,0.4,0.05), limits = c(-0.2,0.4)) +
  labs(x = "Number of days before and after the Lehman Brothers announcement", y = "Obama vote intention\nCoefficient estimates\n(with 90% and 95% confidence intervals)") +
  theme

# To save the figure, please create the Plots folder and execute the below code:
#ggsave("Plots/FigM5_ANES_Obamavoted_incremental_controls.pdf", dpi = 1200, width = 15, height = 10, unit = "in")

```

# End.